I\'m trying to take a branch with changes and bring it back to be identical to the upstream it diverged from. The changes are both local and have been pushed to github, so n
Heavy handed, but hell, what can possibly go wrong?
cp -r .git /tmpgit checkout yrm -rf .git && cp -r /tmp/.git .Another simulation for git merge -s theirs ref-to-be-merged:
git merge --no-ff -s ours ref-to-be-merged # enforce a merge commit; content is still wrong
git reset --hard HEAD^2; git reset --soft HEAD@{1} # fix the content
git commit --amend
An alternative to the double reset would be applying the reverse patch:
git diff --binary ref-to-be-merged | git apply -R --index
You can make a branch look like any other commit with git reset, but you have to do it in a round-about way.
To make a branch on commit <old> look like a commit <new>, you can do
git reset --hard <new>
in order to make <new> the contents of the working tree.
Then do
git reset --mixed <old>
to change the branch back to the original commit but leaving working tree in the <new> state.
Then you can add and commit the changes, in order to make your branch exactly match the contents of the <new> commit.
It's counter-intuitive that to move from the <old> state to the <new> you need to do a git reset from <new> to <old>. However with the option --mixed the working tree is left at <new> and the branch pointer set to <old>, so that when the changes are committed the branch looks how we want.
Don't lose track of your commits, e.g. forget what <old> is when doing git reset --hard <new>.