Jak przeformułować pierwszą wiadomość git commit?

Mam działające drzewo zawierające 3 kommity:

➜ ~ myproject git: (master) git log

commit a99cce8240495de29254b5df8745e41815db5a75
Author: My Name <[email protected]>
Date:   Thu Aug 16 00:59:05 2012 +0200

    .gitignore edits

commit 5bccda674c7ca51e849741290530a0d48efd69e8
Author: My Name <[email protected]>
Date:   Mon Aug 13 01:36:39 2012 +0200

    Create .gitignore file

commit 6707a66191c84ec6fbf148f8f1c3e8ac83453ae3
Author: My Name <[email protected]>
Date:   Mon Aug 13 01:13:05 2012 +0200

    Initial commit (with a misleading message)

Teraz Pragnę reword komunikat commit mojego pierwszego commit (6707a66)

➜ ~myproject git: (master) git rebase -i 6707

(...entering vim)

pick 5bccda6 Create .gitignore file
pick a99cce8 .gitignore edits

# Rebase 6707a66..a99cce8 onto 6707a66
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

W tym przypadku chciałbym poprawić (reword w git parlance) komunikat commit o którym mowa:

Pierwszy commit (z wprowadzającym w błąd Komunikatem)

... do czegoś odpowiednie.

Nic dziwnego, że moja powyższa próba nie powiodła się, ponieważ pierwszy commit oczywiście nie ma żadnego rodzica commita. (A kiedy rebase, musisz odwołać się do następnego najstarszego commit przed do tego, który chcesz reword, prawda?)

Istotą mojego pytania jest zatem to, czy możecie to osiągnąć w jakikolwiek inny sposób?
Author: Henrik, 2012-08-16

3 answers

Do git rebase -i --root

(wskaż root zamiast wskazywać na konkretny commit)

W ten sposób, commit główny jest również dołączony i możesz go po prostu reword Jak każdy inny commit.

Opcja --root została wprowadzona w Git v1.7.12 (2012). Wcześniej jedyną opcją było użycie filter-branch lub amend, co zazwyczaj jest trudniejsze do wykonania.

Uwaga: Zobacz także to podobne pytanie i odpowiedź.

 147
Author: florisla,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-09-24 09:36:40

Zawsze możesz użyć git filter-branch --msg-filter:

git filter-branch --msg-filter \
  'test $GIT_COMMIT = '$(git rev-list --reverse master |head -n1)' &&
echo "Nice message" || cat' master
 12
Author: fork0,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-08-16 18:47:49

Gist Pcreux ma dobry sposób na przeformułowanie pierwszego commita:

# You can't use rebase -i here since it takes the parent commit as argument.
# You can do the following though:
git checkout FIRST_COMMIT_SHA && git commit --amend && git rebase HEAD master
 12
Author: Douglas,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-12-30 13:38:03