git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git merge --no-commit <branch>; does commit

From
Jakub Narebski <jnareb@gmail.com>
Date
Dec 15, 2007, 19:18 UTC
Message-ID
<m37ijfrcm5.fsf@roke.D-201>
In-Reply-To
<alpine.LSU.0.99999.0712151905280.4341@castor.milkiway.cos>
Michael Dressel <MichaelTiloDressel@t-online.de> writes:
Show 22 quoted lines
> On Fri, 14 Dec 2007, Alex Riesen wrote:
> 
>> Michael Dressel, Thu, Dec 13, 2007 22:28:30 +0100:
>>> On Thu, 13 Dec 2007, Alex Riesen wrote:
>>>> On 13/12/2007, Michael Dressel wrote:
>>>>> git merge --no-commit <branch> does "create" a commit. At lesat the
>>>>> head and index are moved to the new commit fetched from <branch>. Maybe
>>>>> that is because git was able to do a fast forward?
>>>>
>>>> Yes. Because fast-forward is what it called: fast-forward.
>>>> It does not do any commits at all.
>>>>
>>>
>>> It looks like I misunderstood the meaning of --no-commit. I have to use
>>> --squash in this case.
>>>
>>
>> Maybe. Or maybe you misunderstood the meaning of --squash, which also
>> is not a merge.
> 
> Since "git merge --squash <branch>" does a merge of <branch> into the
> working tree why would you not call it a merge?

A few illustrations. Commits A, B, C were made on 'trunk', commits a, b, c were made on 'branch'. You are on 'trunk', running "git merge <options> branch". We assume that there are no conflicts.

1. A non fast-forward case
   1---2---3---A---B---C   <-- trunk    <-- HEAD
            \
             \-a---b---c   <-- branch
1.1. "git merge branch"
   1---2---3---A---B---C--M   <-- trunk  <-- HEAD
            \            /
             \-a---b---c/     <-- branch

M is _merge_ commits, with two parents: C and c. It was created by "git merge branch".

1.2. "git merge --no-commit branch"
                        /-------- trunk  <-- HEAD
                       v
   1---2---3---A---B---C--*
            \            /
             \-a---b---c/     <-- branch
                       ^                           
                        \-------- MERGE_HEAD

The merge commit '*' is prepared, but not yet committed, just as if there were merge conflict during merge. "git commit" would commit a merge (and would tell you that it does a merge commit).

1.3. "git merge --no-commit --no-ff branch"
Like in 1.2, because it is non fast-forward case.
1.4. "git merge --squash branch"
   1---2---3---A---B---C--[abc]'   <-- trunk <-- HEAD
            \
             \-a---b---c           <-- branch

"[abc]'" is a _single parent_ commit (it is not a merge commit!) which incorporates changes made on branch as if it were made in a single, large (!) commit.

1.5. "git rebase trunk branch" (or "git pull --rebase branch")
   1---2---3---A---B---C              <-- trunk    
                        \
                         \-a'--b'--c' <-- branch  <-- HEAD

Rebase is step-by-step process, replying commits a, b, c on top of trunk, trying for the same _changes_. a', b', c' are newly created commits, introducing the same changes as a, b, c if there were no rebase conflicts.

I think that "git pull --rebase branch" goes a step further and actually does after-rebase fast-forward merge, and does not change branch, but I might be mistaken.

   1---2---3---A---B---C---a'--b'--c'  <-- trunk <-- HEAD
            \
             \-a---b---c               <-- branch
2. Fast forward case; there are no commits A, B, C, and we
start from the following situation:
   1---2---3               <-- trunk    <-- HEAD
            \
             \-a---b---c   <-- branch
2.1. "git merge branch"
   1---2---3            /----- trunk    <-- HEAD
            \          v
             \-a---b---c   <-- branch

Fast forward results in simply moving the head of trunk. It does not create a commit, hence:

2.2. "git merge --no-commit branch"
Like in 2.1, because fast-forwarding does not create a commit.
2.3. "git merge --no-commit --no-ff branch"
   1---2---3               <-- trunk    <-- HEAD
            \
             \-a---b---c   <-- branch
(probably with some error message).

Test of understanding the concepts: what does "git merge --squash --no-commit" does?

-- 
Jakub Narebski
Poland
ShadeHawk on #git
Previous: Björn SteinbrinkNext: Michael Dressel
Message 8 of 14 in “git merge --no-commit <branch>; does commit”
  1. Michael DresselDec 13, 2007
  2. Alex RiesenDec 13, 2007
  3. Alex RiesenDec 13, 2007
  4. Michael DresselDec 13, 2007
  5. Alex RiesenDec 14, 2007
  6. Michael DresselDec 15, 2007
  7. Björn SteinbrinkDec 15, 2007
  8. Jakub NarebskiDec 15, 2007
  9. Michael DresselDec 15, 2007
  10. Jakub NarebskiDec 15, 2007
  11. Michael DresselDec 15, 2007
  12. Alex RiesenDec 15, 2007
  13. Michael DresselDec 15, 2007
  14. Alex RiesenDec 16, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.