1

I tried to split a big commit which was already pushed in a smaller one following How can I split up a Git commit buried in history?. Now, I made some other changes as well and discarded some useless modifications.

Now I tried a push request, but it failed because I've accidentally removed those commits during rebasing instead of reverting them. git status shows:

$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 15 and 2 different commit(s) each, respectively.
#
nothing to commit (working directory clean)

I already tried cloning the repository, reverting that commit and pushing it. Next, I pulled upstream in my working directory. That does not work and is basically applying my new modifications and then reverting everything again to the old state.

How can I insert those 2 commits (fast-forward?) before my commits with a revert commit after it? Do I need to do another rebase?

My commits looks like this:

A - B - C         origin/master
     \
      D - E - F   local working copy

I want it looks like this:

A - B - C - revert_B - D - E - F
Community
  • 1
  • 1
Lekensteyn
  • 64,486
  • 22
  • 159
  • 192

1 Answers1

2

Yes, you just need another rebase. If master is at F, then do something like this:

git checkout -b tmp origin/master
git revert B
git rebase tmp master
git branch -d tmp
Ryan Stewart
  • 126,015
  • 21
  • 180
  • 199
  • Updated my answer. That should take care of it. – Ryan Stewart Aug 04 '11 at 16:52
  • I'm getting a warning: "warning: not deleting branch 'tmp' that is not yet merged to 'refs/remotes/origin/master', even though it is merged to HEAD. error: The branch 'tmp' is not fully merged. If you are sure you want to delete it, run 'git branch -D tmp'.". Does this occur because I made a commit in `tmp` without pushing it to master? (is it safe to proceed removing it?) – Lekensteyn Aug 04 '11 at 17:11
  • To answer my last comment: the error message indeed occurs because the changes haven't been pushed yet. I just pushed and `git branch -d tmp` yields no warning after. – Lekensteyn Aug 04 '11 at 17:44
  • Sorry about that. I didn't realize it would warn if you hadn't pushed. Glad you got it sorted out. – Ryan Stewart Aug 04 '11 at 17:52