2012-04-18 5 views
2

그래서 가끔씩 위로 키를 너무 많이 누르거나 몇 번 누른 다음 ./foo_test 대신 git commit -am "changed foo"을 처리하는 실수를 저지르고, 그 결과 내 레포에서 처리해야하는 추가 커밋이 발생합니다. git가 이전 커밋 된 커밋의 메시지와 일치하는 커밋을 거부 할 수 있습니까?이전 커밋과 동일한 메시지로 git commit을 거부 하시겠습니까?

+2

1 단지 보조 노트로 :'자식 어쨌든 좋은 연습으로 간주되지 않습니다 -a' 커밋합니다. 매번 커밋 할 내용을 검토하는 것이 좋습니다. 일반적인 워크 플로우는'git status','git add '또는'git add -a', 그리고'git commit'입니다. – penartur

+0

당신은 pre-commit hook을 설정할 수 있습니다. http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes이 경우에는 제안대로 쉽게 취소 할 수 있습니다. – ngm

답변

6

완전히 거부하지 말고 그냥 취소하지 않으시겠습니까?

# Leaves all changes as 'changes to be committed', but 
# uncommits the most recent commit 
git reset --soft HEAD~ 
# Leaves all changes as changed working copy files (ie, 
# unstages them as well) 
git reset HEAD~ 
# Lets you edit the most recent commit message 
git commit --amend 
# Lets you do bulk surgery on your revision history, deleting 
# or merging dozens of commits in one operation 
git rebase -i <last good commit, eg origin/mainline> 

당신이 정말로이 .git/hooks/prepare-commit-msg를 확인, 즉시 거부되도록하려면

-. 당신이 ( git cat-file commit HEAD 통해) 최신 커밋 메시지를 얻을 전달 된 커밋 메시지에 비교가 스크립트를 추가 할 수 있습니다 서로 일치하면 커밋을 중단하려면 exit 1.

0

확인할 커밋 후크 스크립트를 사용하십시오.

만약 같은, 다음 자식 리셋 --mixed HEAD ~

관련 문제