How to stop merging in git?

I had a merge with three ways to merge:

git checkout master git merge BranchA >> Fast-forward merge git merge BranchB >> Three-way-merge (prompts for a merge commit message) 

My questions are two:

  • How can I abort a merge? With a three-way merge, I show the editor where to write the merge message. But if I exit without saving, git will continue to merge anyway (just a merge-commit message will be the default instead of the one I could write, but interrupted)

     commit 11111233 Merge 'BranchB' into master 

    although obviously without confirming the commit message, I would expect the merge to not happen (like the same behavior when I DO NOT confirm the normal commit message)

  • Will the commits from the two merged branches be sorted in chronological order ? Or first (in git log ) will I see a commit from BranchA , then THEN from BranchB commits ?

EDIT

To better explain the second question, I did a test: 2 branches (A and B), starting from the leading branch. I committed to B, then to A, then again to B, and finally again to A. Then I combined BranchA into masters. And then BranchB's master.

But when I git log on the host, this is what happened and why I asked the second question:

 commit 730fdd4d328999c86fa4d3b6120ac856ecaccab1 Merge: 7eb581b cc1085a Author: Arthur Conandoyle < Arthur.Conandoyle@live.com > Date: Mon Feb 9 21:24:27 2015 +0100 Merge branch 'BranchB' into master_COPY commit 7eb581b39a8402e1694cc4bf4eab4a3feb1143f8 Author: Arthur Conandoyle < Arthur.Conandoyle@live.com > Date: Mon Feb 9 21:23:18 2015 +0100 BranchA) - This should be the (second) last change of the branch, and be the most recent into the git log, even if I merge another branch into master, AFTER the one where we are committing this. commit cc1085a6aaa2ee4b26d3c3fbb93bee863d9e7c28 Author: Arthur Conandoyle < Arthur.Conandoyle@live.com > Date: Mon Feb 9 21:20:29 2015 +0100 (BranchB) - Add settings to the last new features commit 5f5b846a2f89886d01244ba77af941f554233b51 Author: Arthur Conandoyle < Arthur.Conandoyle@live.com > Date: Mon Feb 9 21:18:54 2015 +0100 (BranchA) - Add some changes commit 92a57a56b6b7c9694fbedda71b8070fc58683dde Author: Arthur Conandoyle < Arthur.Conandoyle@live.com > Date: Mon Feb 9 21:18:17 2015 +0100 (BranchB) - Some changes commit 221765476e348833cf8da73b1bf5239f3d4240e8 Author: Arthur Conandoyle < Arthur.Conandoyle@live.com > Date: Tue Feb 3 12:12:19 2015 +0100 Change (this is the last commit of the parent 'master' branch) 

(As Srdjan Grubor wrote), I would first expect (in chronological order) all the commits from the combined BranchA and THEN all the commits from the combined BranchB, following the merge order ... .. but itโ€™s ridiculous to show them in chronological order instead of git log , and commits are not shown as grouped in branches!

+5
source share
3 answers

The BranchB merge is completely normal, requesting a regular commit message. There by default, if you exit without change, the merge will be completed. Since the merge itself has succeeded, the only way to stop it now is to send a message about the bad merge (its missing hooks will make it empty).

When the merge has stopped, you can abort it with

 git merge --abort # or git reset --merge 

Indenting everything you just mistakenly

 git reset --hard @{1} 

In the concept of git there are no concepts of "branch ownership", all the ways in which you can refer to a commit are equal.

You can get a better idea of โ€‹โ€‹the structure of git log shows you

 git log --graph --decorate --oneline 

Try using --date-order and --topo-order and --all .

+14
source

As for your editing, git log sorts its output. This may surprise even in a linear story. Flags exist to change the sorting method , and adding --graph changes the default sorting to --topo-order .

Another note is that when git fast-forwards a branch, no comming occurs:

  C---D <-- branch / A---B <-- mainline 

Providing a mainline to get the branch with a quick jump to a simple graph:

  C---D <-- mainline, branch / A---B 

which is trivially drawn as a simple straight line, but forcing the merge (with git merge --no-ff ) forces the actual bipolar merge:

  C---D <-- branch / \ A---B-------M <-- mainline 

which (after summarizing, to have more commits) presents more interesting parameters for the commit sorting process.

+2
source

You can abort the merge after completion and use

 git reflog 

to return to the previous state of the tree. Usually merges are not sorted in chronological order, but in the order of fixing the branches, which are then sorted separately. This means that you will see that your merge join, followed by all the final branches of the record (in chronological order), followed by your main branch, commits (in chronological order).

0
source

Source: https://habr.com/ru/post/1212986/


All Articles