2

I pushed some changes to our central git repository, and then immediately realized that I had an old, now obsolete change lying around, and that I had introduced a merge with it:

before

I then used git rebase to get rid of this spurious parent:

after

Then I pushed this with git push -f to origin. It answers with "everything up-to-date".

Now I would expect the central repository to match what I have locally. However, when I clone the project anew, I still have the spurious parent inside. What's worse is that git wants to merge, and if I let it do that, I get my latest commit twice (once with the old hash, and once with the new one after rebasing).

How do I get git to push what I have without merging, and just take my repository state as the new state (so basically, to reject all remote differences)?

or am I doing this wrong? I want to get rid of the "When reading a property..." commit, and the whole red line in the upper image.

jdm
  • 9,470
  • 12
  • 58
  • 110

1 Answers1

1

You can solve this in various ways. One way is to reconstruct the history locally by using reset, stash and commit. The following will undo your last commit (Initial import of the...) and stash away those changes.

git reset --mixed HEAD^
git stash

Now you can reset your master to the commit you had before you did the merge, assuming abcd1234 is the hash of the "Testing git." commit:

git reset --hard abcd1234

Now bring back the stash and commit it again:

git stash pop
git add .
git commit -m 'Initial import of the C++ client library.'

Now finally push up your rewritten master:

git push -f origin master
rtn
  • 127,556
  • 20
  • 111
  • 121
  • Thanks, it worked! Didn't know about `stash`. I also had to change `receive.denyNonFastForwards` to get it to accept the push (http://stackoverflow.com/a/1377930/143091). – jdm Apr 06 '12 at 12:09
  • That's why your first push didn't work after you did the rebase. Makes sense. – rtn Apr 06 '12 at 14:47
  • And btw, stash is a life saver! Also very useful if you're working on something and need to do a quick fix. Just stash your changes, do other stuff and bring it back when you're done with the side quest. You can also store any number of stashes, it just adds the new changes to the stash stack. – rtn Apr 06 '12 at 14:49