You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/07-git-tools/sections/advanced-merging.asc
+3-5Lines changed: 3 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -493,10 +493,10 @@ There are two ways to approach this problem, depending on what your desired outc
493
493
===== Fix the references
494
494
495
495
If the unwanted merge commit only exists on your local repository, the easiest and best solution is to move the branches so that they point where you want them to.
496
-
In most cases, if you follow the errant `git merge` with `git merge --abort`, this will reset the branch pointers so they look like this:
496
+
In most cases, if you follow the errant `git merge` with `git reset --hard HEAD~`, this will reset the branch pointers so they look like this:
497
497
498
-
.History after `git merge --abort`
499
-
image::images/undomerge-reset.png[History after `git reset --merge`.]
498
+
.History after `git reset --hard HEAD~`
499
+
image::images/undomerge-reset.png[History after `git reset --hard HEAD~`.]
500
500
501
501
We covered `reset` back in <<_git_reset>>, so it shouldn't be too hard to figure out what's going on here.
502
502
Here's a quick refresher: `reset --hard` usually goes through three steps:
@@ -506,8 +506,6 @@ Here's a quick refresher: `reset --hard` usually goes through three steps:
506
506
. Make the index look like HEAD.
507
507
. Make the working directory look like the index.
508
508
509
-
In the case of `git merge --abort`, Git is actually running a `git reset --merge` and when doing so, Git is extra careful with steps 2 and 3 to preserve any changes you've made in the working directory or the index, but otherwise works as though this were a `--hard` reset.
510
-
511
509
The downside of this approach is that it's rewriting history, which can be problematic with a shared repository.
512
510
Check out <<_rebase_peril>> for more on what can happen; the short version is that if other people have the commits you're rewriting, you should probably avoid `reset`.
513
511
This approach also won't work if any other commits have been created since the merge; moving the refs would effectively lose those changes.
0 commit comments