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

who's on first? - following first parent and merge-management

From
NKNeal Kreitzinger <nkreitzinger@gmail.com>
Date
Mar 7, 2012, 05:36 UTC
Message-ID
<jj6s47$m98$1@dough.gmane.org>
"first parent" and "follow first parent" are mentioned frequently in git 
documentation.  This seems to imply that its pretty important.  That 
would imply it should be intentional (planned).  Who is "first parent"? 
  Who is "first parent" _meant_ to be?  What is "follow first parent" 
_meant_ to show?

(I've been on the rebase track until now so I'm "new" to git-merge's.) Symptomatically, I think "first parent" is the branch you were on when you did the merge. That would mean the first parent can change depending on your merge-management practices. This affects the results that "follow first parent" produces. For example:

$ git log --first-parent --oneline origin/master deadbee some commit x

Scenario A: "First-Parent Flip-Flop" (some users are doing this)

(1) I commit on local master. USER=foo $ git checkout master && hack && git commit -a -m "foo commit 1" $ git log --first-parent --oneline master foo1111 foo commit 1 deadbee some commit x

(2) You push to canonical master. USER=bar $ git checkout master && hack && git commit -a -m "bar commit 1" $ git log --first-parent --oneline master bar1111 bar commit 1 deadbee some commit x $ git push origin HEAD && git fetch origin $ git log --first-parent --oneline origin/master bar1111 bar commit 1 deadbee some commit x

(3) I merge canonical master w/my master and push. USER=foo $ git checkout master && git pull origin $ git log --first-parent --oneline master mrg1111 Merge branch 'master' of file:///root/BARE foo1111 foo commit 1 deadbee some commit x $ git push origin HEAD && git fetch origin $ git log --first-parent --oneline origin/master mrg1111 Merge branch 'master' of file:///root/BARE foo1111 foo commit 1 deadbee some commit x

(4) You merge canonical master w/your master and push. USER=bar $ git checkout master && hack && git commit -a -m "bar commit 2" $ git log --first-parent --oneline master bar2222 bar commit 2 bar1111 bar commit 1 deadbee some commit x $ git pull origin $ git log --first-parent --oneline master mrg2222 Merge branch 'master' of file:///root/BARE bar2222 bar commit 2 bar1111 bar commit 1 deadbee some commit x $ git push origin HEAD && git fetch origin $ git log --first-parent --oneline origin/master mrg2222 Merge branch 'master' of file:///root/BARE bar2222 bar commit 2 bar1111 bar commit 1 deadbee some commit x

This "flip-flop" practice does not seem right to me.  Please comment.

Scenario B: "First-Parent Consistency" (1) I commit on local master. USER=foo $ git checkout -b foo-topic master && hack && git commit -a -m "foo commit 1" $ git log --first-parent --oneline foo-topic foo1111 foo commit 1 deadbee some commit x

(2) You push to canonical master. USER=bar $ git checkout -b bar-topic master && hack && git commit -a -m "bar commit 1" $ git log --first-parent --oneline bar-topic bar1111 bar commit 1 deadbee some commit x $ git checkout master && git merge bar-topic && git push origin HEAD && git fetch origin $ git log --first-parent --oneline origin/master bar1111 bar commit 1 deadbee some commit x

(3) I merge --no-ff into master and push. USER=foo $ git checkout master && git pull --ff-only origin $ git log --first-parent --oneline master bar1111 bar commit 1 deadbee some commit x $ git-merge foo-topic $ git log --first-parent --oneline master mrg1111 Merge branch 'foo-topic' bar1111 bar commit 1 deadbee some commit x $ git push origin HEAD && git fetch origin $ git log --first-parent --oneline origin/master mrg1111 Merge branch 'foo-topic' bar1111 bar commit 1 deadbee some commit x

(4) You merge --no-ff into master and push. USER=bar $ git checkout bar-topic && hack && git commit -a -m "bar commit 2" $ git log --first-parent --oneline bar-topic bar2222 bar commit 2 bar1111 bar commit 1 deadbee some commit x $ git checkout origin && git pull --ff-only origin $ git log --first-parent --oneline master mrg1111 Merge branch 'foo-topic' bar1111 bar commit 1 deadbee some commit x $ git merge bar-topic $ git log --first-parent --oneline master mrg2222 Merge branch 'bar-topic' mrg1111 Merge branch 'foo-topic' bar1111 bar commit 1 deadbee some commit x $ git push origin HEAD && git fetch origin $ git log --first-parent --oneline origin/master mrg2222 Merge branch 'bar-topic' mrg1111 Merge branch 'foo-topic' bar1111 bar commit 1 deadbee some commit x

This "consistency" scenario seems better, but I'm not sure if its right. 
  Git seems to "like it" in that the merge messages make more sense. 
Please comment.

Please advise on "first parent" intent, best-practices, and pitfalls, or documentation that explains it. (I haven't found documentation that directly explains "first parent theory and practice". I've seen many references to "first parent" and its implied meaning that I'm supposed to "just know" or deduce).

Thanks in advance for any pointers.

v/r, neal

Next: Junio C Hamano
Message 1 of 13 in “who's on first? - following first parent and merge-management”
  1. Neal KreitzingerMar 7, 2012
  2. Junio C HamanoMar 7, 2012
  3. Junio C HamanoMar 8, 2012
  4. Jeff KingMar 8, 2012
  5. Junio C HamanoMar 8, 2012
  6. Johannes SixtMar 8, 2012
  7. Junio C HamanoMar 8, 2012
  8. Holger HellmuthMar 9, 2012
  9. Johannes SixtMar 9, 2012
  10. Holger HellmuthMar 9, 2012
  11. Junio C HamanoMar 9, 2012
  12. Jonathan NiederMar 8, 2012
  13. Junio C HamanoMar 8, 2012

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.