Skip to content

Instantly share code, notes, and snippets.

@lava
Last active November 21, 2018 13:54

Revisions

  1. lava revised this gist Nov 21, 2018. 1 changed file with 33 additions and 0 deletions.
    33 changes: 33 additions & 0 deletions git_merge.md
    Original file line number Diff line number Diff line change
    @@ -69,6 +69,39 @@ direction to get the PR number:
    8e5204a Add second.


    ## Showing a history with only "correct" merges

    For this I tried adding new branch `fourth` (basing off master) and `initial2` (basing off the initial commit) where `initial2`
    is merged into `fourth` before `fourth` is merged into master using `--no-ff`.

    bevers@poincare:~/code/git$ git log --graph --oneline
    * 35fc573 (HEAD -> master) Merge branch 'fourth'
    |\
    | * 195e250 (fourth) Merge branch 'initial2' into fourth
    | |\
    | | * 509c299 (initial2) Add initial2.
    | * | c133ca1 Add fourth.
    |/ /
    * | 044c523 Merge branch 'third'
    |\ \
    | * | 080a881 Third.
    |/ /
    * | ab286d7 Merge branch 'second'
    |\ \
    | |/
    |/|
    | * 8e5204a Add second.
    |/
    * 66ee9d4 Initial.

    It looks like this makes it very hard to view a history with only the merge commits where branches where merged into master:

    35fc573 (HEAD -> master) Merge branch 'fourth'
    195e250 Merge branch 'initial2' into fourth
    044c523 Merge branch 'third'
    ab286d7 Merge branch 'second'


    ## Bisecting on merge commits

    I wanted to try this as well since it came up in the comments, but
  2. lava renamed this gist Nov 21, 2018. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. lava created this gist Nov 21, 2018.
    75 changes: 75 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,75 @@
    # Testing the `--no-ff` merge strategy

    I created a sample git repository by creating branches
    `second` and `third` adding a file with the same name
    each, and then rebasing the branches and merging them
    using `git merge --no-ff`:

    bevers@poincare:~/code/git$ ls
    initial second third

    bevers@poincare:~/code/git$ git log --graph --oneline
    * 044c523 (HEAD -> master) Merge branch 'third'
    |\
    | * 080a881 Third.
    |/
    * ab286d7 Merge branch 'second'
    |\
    | * 8e5204a Add second.
    |/
    * 66ee9d4 (first2) Initial.

    Below I list several observations.

    ## Behaviour of `HEAD`

    bevers@poincare:~/code/git$ git log --oneline
    044c523 (HEAD -> master) Merge branch 'third'
    080a881 Third.
    ab286d7 Merge branch 'second'
    8e5204a Add second.
    66ee9d4 Initial.

    bevers@poincare:~/code/git$ git show --oneline HEAD~1
    ab286d7 Merge branch 'second'

    I would have expected `HEAD~1` to point at `080a881`.


    ## Viewing the contents of commits

    bevers@poincare:~/code/git$ git log --stat --oneline
    044c523 (HEAD -> master) Merge branch 'third'
    080a881 Third.
    third | 0
    1 file changed, 0 insertions(+), 0 deletions(-)
    ab286d7 Merge branch 'second'
    8e5204a Add second.
    second | 0
    1 file changed, 0 insertions(+), 0 deletions(-)
    66ee9d4 (first2) Initial.
    initial | 0
    1 file changed, 0 insertions(+), 0 deletions(-)

    bevers@poincare:~/code/git$ git log --stat --oneline --merges
    044c523 (HEAD -> master) Merge branch 'third'
    ab286d7 Merge branch 'second'

    bevers@poincare:~/code/git$ git log -p --oneline --merges
    044c523 (HEAD -> master) Merge branch 'third'
    ab286d7 Merge branch 'second'

    This also has implications for tasks like finding out the PR in
    which a particular file was last touched: Because the merge
    commit itself does not change the file, it does not show up in
    `git blame` etc. and we would have to walk the log in reverse
    direction to get the PR number:

    bevers@poincare:~/code/git$ git log --oneline -- second
    8e5204a Add second.


    ## Bisecting on merge commits

    I wanted to try this as well since it came up in the comments, but
    I don't know how to do it. Suggestions?