git squash与被追踪的分支分道扬..

时间:2014-05-27 13:20:12

标签: 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,则提交更改将丢失。

任何帮助?

1 个答案:

答案 0 :(得分:1)

你在这里改变git历史。您需要强制推送(从而覆盖远程历史记录),或将更改推送到新分支。每当需要变基时,我通常会做后者。

另外,请确保在重新安装之前执行git pull