2017-02-08 1 views
1

특정 커밋을 완전히 삭제하고 싶습니다. 커밋을 완전히 삭제할 수 있습니까?

나는이 실험을했다 :

초기화의 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의 어딘가에 있으며 실제로 지워지지는 않습니다.

이 기록을 완전히 지울 수 있습니까?

+2

FWIW,이 경우에는 rebase dance 대신에''git commit --amend''를 사용해야합니다. –

+0

중복이 올바른 답을 가지고 있기 때문에 이것을 duplicate로 표시했습니다 (Andreas Wederbrand의 답변에서 reflog 항목을 만료 시키거나 삭제 한 다음 * git gc를 사용하거나 저장소를 복제하고 삭제할 수 있음). 더 획기적인 원본). 그러나, 나는 일반적으로 가장 적용 가능하기 때문에 exussum의 답변을 upvoted. – torek

답변

1

그것은 결국 삭제 얻을 것이다하지만 당신이 정말로 필요한 경우는 git gc 당신은 정말 확인 매달려 제거 커밋 할 --aggressive--prune=all 그것을 실행하는 데 필요한 수동

를 실행할 수 있습니다 제거 커밋.

+0

'git gc --aggressive --prune = all'을 시도했지만, 여전히 SHA로 오인 된 커밋으로 돌아갈 수 있습니다. –

4

자식은 (커밋, 이동 지점 등을 리베이스) 그들에게이 역사의 모든 당신이 만든 변경 사항이 표시됩니다

git reflog 

를 사용하여 볼 수 있습니다 주위에 이러한 커밋의 모든 보관, 게으른

그들은 가비지 컬렉터를 청소해야하지만 솔직히이 기능은 더 귀찮은 도움이됩니다. 공간의 작은 양을 위해 나는 그것을 걱정하지 않을 것이다 사용할 것이다.

0

유형 git reflog 다양한 커밋 메시지와 헤드 번호를 표시합니다. 유형 자식 재설정 - 머리 머리 (머리 번호는 여기에 입력). 헤드 번호는 프로젝트를 되돌리려는 곳입니다. 경고 : 되 돌린 후에는 그 시점으로 돌아갈 수 없습니다.

+0

하지만 커밋은 여전히있을 것입니다. 내가 그 SHA를 알고있는 한 그 잘못된 커밋으로 돌아갈 수 있습니다. 그 커밋을 완전히 삭제하고 싶습니다. –

+0

이 링크를 클릭하십시오. 도움이 될지도 모릅니다. https://github.com/blog/2019-how-to-undo-almost-anything-with-git – Intelligent

관련 문제