简体   繁体   中英

git squash diverged from tracked branch

I'm trying to squash some commits from a branch I'm tracking from a github repository (and also in my internal gitolite server). My problem is that I'm rebasing as explained at http://www.git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits , squash is done, but then my branch diverges from github one and I can't push changes to it.

Initially I have my branch updated:

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)

This is my log:

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.

...

Now, I'm doing the rebase with:

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

in the edit screen:

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 is done and I get:

[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.

but then, my branch has diverged from upstream, so I can't push those changes:

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)
...

Then, If I run git pull, commit changes are lost.

Any help?

You're changing git history here. You either need to force the push (thereby overriding the remote history), or push your changes to a new branch. I usually do the latter whenever a rebase is needed.

Also, make sure you do a git pull before you rebase.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM