programing

Git에서 루트 커밋을 편집하시겠습니까?

javajsp 2023. 5. 9. 22:04

Git에서 루트 커밋을 편집하시겠습니까?

이후 커밋에서 메시지를 변경할 수 있습니다.

git commit --amend                    # for the most recent commit
git rebase --interactive master~2     # but requires *parent*

부모가 없는 첫 번째 커밋의 커밋 메시지를 어떻게 변경할 수 있습니까?

Git 버전 1.7.12부터 이제 사용할 수 있습니다.

git rebase -i --root

문서화

작업 트리가 깨끗하다고 가정하면 다음 작업을 수행할 수 있습니다.

# 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

ecdpalma의 답변을 확장하려면 이제 다음을 사용할 수 있습니다.--root말할 수 있는 옵션rebase루트/첫 번째 커밋을 다시 작성하려는 경우:

git rebase --interactive --root

그런 다음 루트 커밋이 기본 TODO 목록에 표시되고 편집 또는 다시 쓰기를 선택할 수 있습니다.

reword <root commit sha> <original message>
pick <other commit sha> <message>
...

의 설명은 다음과 같습니다.--rootGitrebase 문서(광산 강조)에서:

연결할 수 있는 모든 커밋 기본 재배치<branch>그들을 제한하는 대신에<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

언급URL : https://stackoverflow.com/questions/2119480/edit-the-root-commit-in-git