gitのルートコミットを編集しますか?
-
22-09-2019 - |
質問
メッセージを後のコミットから変更する方法があります。
git commit --amend # for the most recent commit
git rebase --interactive master~2 # but requires *parent*
最初のコミットのコミットメッセージをどのように変更できますか(親はいません)?
解決
きれいな作業木があると仮定すると、次のことを行うことができます。
# checkout the root commit
git checkout <sha1-of-root>
# amend the commit
git commit --amend
# rebase all the other commits in master onto the amended root
git rebase --onto HEAD HEAD master
他のヒント
Gitバージョンのように 1.7.12, 、今使用することができます
git rebase -i --root
拡張する Ecdpalmaの答え, 、これで使用できます --root
伝えるオプション rebase
ルート/最初のコミットを書き直したいこと:
git rebase --interactive --root
その後、ルートコミットはRebase Todoリストに表示され、編集または再編集を選択できます。
reword <root commit sha> <original message>
pick <other commit sha> <message>
...
これが説明です --root
から Git Rebase Docs (私の強調):
到達可能なすべてのコミットをリバースします
<branch>
, 、anでそれらを制限する代わりに<upstream>
. これにより、ブランチでルートコミットを再度再加速できます.
より高い評価の回答に代わるものを提供するために:
レポを作成していて、将来の「最初の」本当のコミットに加えてリベースすることを前もって知っている場合、最初に明示的な空のコミットを行うことで、この問題を完全に回避できます。
git commit --allow-empty -m "Initial commit"
そしてその後、「本物の」コミットを始めます。たとえば、標準的な方法をコミットすることの上に簡単にリベースできます。 git rebase -i HEAD^
使用できます git filter-branch
:
cd test
git init
touch initial
git add -A
git commit -m "Initial commit"
touch a
git add -A
git commit -m "a"
touch b
git add -A
git commit -m "b"
git log
-->
8e6b49e... b
945e92a... a
72fc158... Initial commit
git filter-branch --msg-filter \
"sed \"s|^Initial commit|New initial commit|g\"" -- --all
git log
-->
c5988ea... b
e0331fd... a
51995f1... New initial commit
所属していません StackOverflow