특정 커밋을 완전히 삭제하고 싶습니다. 커밋을 완전히 삭제할 수 있습니까?
나는이 실험을했다 :초기화의 repo
bash-3.2$ git init
Initialized empty Git repository in /Users/*****/test/.git/
커밋이 생성 파일
bash-3.2$ touch readme
bash-3.2$ ls
readme
을 만듭니다
bash-3.2$ git add .
bash-3.2$ git commit -m "first commit"
[master (root-commit) b9f8e60] first commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 readme
파일 (일부 실수가 있었) 것을
편집
bash-3.2$ echo WrongMsg > readme
bash-3.2$ cat readme
WrongMsg
부주의 로그가
bash-3.2$ git log --oneline
지금
1eec681 careless commit
b9f8e60 first commit
을 줄 것이다 변경
bash-3.2$ git add .
bash-3.2$ git commit -m "careless commit"
[master 1eec681] careless commit
1 file changed, 1 insertion(+)
검사를 커밋, 나는 인정 출력됩니다
Successfully rebased and updated refs/heads/master.
검사 로그
다음, 그런 실수와는bash-3.2$ git rebase -i HEAD^
drop
에
pick 1eec681 careless commit
# Rebase b9f8e60..1eec681 onto b9f8e60 (1 command)
#
# 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
# d, drop = remove commit
#
# 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
변화 pick
메시지를 표시합니다 해결하려면 다음 :wq
저장하기
bash-3.2$ git log --oneline
b9f8e60 first commit
는 실수
bash-3.2$ echo CorrectMsg > readme
bash-3.2$ cat readme
CorrectMsg
bash-3.2$ git add .
bash-3.2$ git commit -m "correction"
[master f224289] correction
1 file changed, 1 insertion(+)
로그
bash-3.2$ git log --oneline
f224289 correction
b9f8e60 first commit
그 드롭의 성공을 것 같다,하지만 커밋을 수정 난이 실행하는 경우 :
bash-3.2$ git reset --hard 1eec681
HEAD is now at 1eec681 careless commit
bash-3.2$ git log --oneline
1eec681 careless commit
b9f8e60 first commit
B를 ANG, 역사는 아직 repo의 어딘가에 있으며 실제로 지워지지는 않습니다.
이 기록을 완전히 지울 수 있습니까?
FWIW,이 경우에는 rebase dance 대신에''git commit --amend''를 사용해야합니다. –
중복이 올바른 답을 가지고 있기 때문에 이것을 duplicate로 표시했습니다 (Andreas Wederbrand의 답변에서 reflog 항목을 만료 시키거나 삭제 한 다음 * git gc를 사용하거나 저장소를 복제하고 삭제할 수 있음). 더 획기적인 원본). 그러나, 나는 일반적으로 가장 적용 가능하기 때문에 exussum의 답변을 upvoted. – torek