My local tree has diverged from the master:
$ git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 7 and 3 different commit(s) each, respectively.
#
nothing to commit (working directory clean)
I tried git pull –rebase and failed:
$ git pull --rebase
First, rewinding head to replay your work on top of it...
Applying: * ...
Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
Auto-merging ChangeLog
CONFLICT (content): Merge conflict in ChangeLog
Failed to merge in the changes.
Patch failed at 0001 * ...
So I reverted with git rebase –abort and I am now at square 1.
What I want is:
- “Export” my 7 patches into human readable diff files (a la hg export).
- Make my tree a carbon copy of the origin/master (a la hg strip).
- re-apply my 7 patches one-by-one by hand (a la hg import).
I do understand that git rebase –continue does this.
I did it and it did work (after a few manual merges and a git add).
However, I want to be able to do that manually,
so I am wondering what are the git commands corresponding to the hg commands above.
Thanks.
PS. Please do not tell me that using a ChangeLog file with git is stupid.
Even if it is, it is not up to me.
There are, of course, several ways you could do this manually. You’ll still have the same conflicts because git is basically doing this for you under the hood. But if you want to do this manually, here are a couple of ways.
First, export your commits as a series of patches. The easiest way to do this is using
git format-patch:will produce 7 patch files — one for each of your commits. (Note that “@{upstream}” is literal — it’s a not so well known feature of git.) This is better than capturing the output of
git diffbecause all of the commit information (author, date, message, etc.) are preserved.Then you could reset your repository to match the upstream:
Then you can re-apply your patches using
git am— either one at a time or all at once.A second option would be to create a spare branch with your work on it:
Then reset your branch to the upstream:
Then cherry-pick the commits over:
Then trash the scrap branch: