Git squash从跟踪分支分叉



我正在尝试从github存储库(以及我的内部gitolite服务器)跟踪分支中压缩一些提交。我的问题是,我在http://www.git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits上解释的重新定位,壁球完成了,但然后我的分支偏离github一个,我不能推动它的变化。

最初我更新了我的分支:

amateo@joshua:~/puppetcode/apache$ git status
On branch squash_test
Your branch is up-to-date with 'github/squash_test'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)
    nohup.out
    spec.log
    spec/acceptance/nodesets.kk/
    tests/spec_dot.pp
nothing added to commit but untracked files present (use "git add" to track)

这是我的日志:

commit 121881d85b93a0b6b851a33d2cc0321196b90f6d
Author: Angel L. Mateo <myemail>
Date:   Tue May 27 11:31:24 2014 +0200
  Add apache::dotconf parameters' documentation
commit c51f6b268a8b22e2c84f93d95ee0b98599770269
Author: Angel L. Mateo <myemail>
Date:   Tue May 27 11:31:24 2014 +0200
  Add apache::dotconf parameters' documentation
commit 82f76d50795eed9839b88745dbabfebe55d8e6bf
Author: Angel L. Mateo <myemail>
Date:   Tue May 27 11:29:19 2014 +0200
  errata
commit 0c3f836e09bb30dac7a969b9d71176bb2e393a73
Author: Angel L. Mateo <myemail>
Date:   Tue May 27 10:58:03 2014 +0200
  Add apache::dotconf documentation
commit bce9951f34c04c8dc0e63ae59dc6922ec70866c2
Author: Angel L. Mateo <myemail>
Date:   Mon May 26 14:47:14 2014 +0200
  A more complete acceptance test.
...

现在,我用:

做重置
amateo@joshua:~/puppetcode/apache$ git rebase -i -k --no-ff -m HEAD~6

编辑界面:

pick 9e027da Fix allignment                                                          
squash 35cb85e Move template to fixtures directory (as it is only for rspec tests)   
squash bce9951 A more complete acceptance test.                                      
squash 0c3f836 Add apache::dotconf documentation                                     
squash 82f76d5 errata                                                                
squash c51f6b2 Add apache::dotconf parameters' documentation                         
squash 121881d Add apache::dotconf parameters' documentation                         
# Rebase b1ddc75..121881d onto b1ddc75                                               
...

rebase完成后,我得到:

[detached HEAD 9f1ce65] Fix allignment
 4 files changed, 101 insertions(+), 3 deletions(-)
 rename {templates => spec/fixtures/templates}/spec.erb (100%)
Successfully rebased and updated refs/heads/squash_test.

但是,我的分支已经从上游分离,所以我不能推动这些更改:

amateo@joshua:~/puppetcode/apache$ git status
On branch squash_test
Your branch and 'github/squash_test' have diverged,
and have 1 and 11 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)
...

然后,如果我运行git pull,提交的更改将丢失。

帮忙吗?

你正在修改git的历史记录。您要么需要强制推送(从而覆盖远程历史记录),要么将更改推送到新的分支。每当需要重基时,我通常使用后者。

此外,确保在您重新定位之前做一个git pull

最新更新