Got a file that has two commits of interest, both on the Master
branch, both only modifying a single file foo
: a previous commit AA
, and the current version in HEAD
. I would like to merge the two versions of the file, keeping bits of both, into HEAD
on Master
.
I did the simplest thing that I thought would work:
git checkout -b merge-purgatory AA
git commit -m "pulled foo back from previous commit for merging into HEAD."
git checkout master
git merge merge-purgatory
Which simply overwrites the current HEAD
version of foo
with AA
version.
Tried the more verbose git checkout -m
as well, same result: a dumb overwrite.
How do I force git to treat the AA
version of foo
as a conflicting merge with the current HEAD
version?
You can use the Git reset command to undo a merge. Firstly, you need to check for the commit hash (or id) so you can use it to go back to the previous commit. To check for the hash, run git log or git reflog . git reflog is a better option because things are more readable with it.
Usually git does not overwrite anything during merge.
If git's merge isn't doing what you want, you could do the following instead:
foo
, e.g. by making sure that git status
is clean.foo
with the version from AA
using: git show AA:foo > foo
foo
that you want with: git add -p foo
foo
with git checkout -- foo
git commit
Alternatively, if you'd rather use a graphical diff tool (such as meld
), you could just do:
git show AA:foo > old-foo
meld old-foo foo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With