2014-01-06 88 views
0

我加入了很多的大量文件的行中的一個項目,然後我做了一個犯任何變化。現在我想刪除該提交及其所有更改。我的意思是我想刪除的承諾,並用它與承諾完成代碼的所有變化。刪除Git中提交併與它

+0

可能重複[如何撤消上一次Git提交?](http://stackoverflow.com/questions/927358/how-to-undo-the-last-git-commit) –

回答

2

要刪除最後一個完全承諾?如果你想更謹慎

git reset HEAD^ --hard 

,你可以在兩個步驟做:在這裏,你走了,但小心,你不能撤消此

git reset HEAD^  # reset HEAD to previous commit but without changing files 
git status   # review the changes that were in the last commit 
git diff --cached # review the changes that were in the last commit 
git reset --hard # *really* undo 
2

git reset方法,通過亞諾什描述工作正常,但完全抹殺提交很少是必要的,如果你養成習慣很容易在你不能處理的情況下結束了。

除非核彈攻擊提交的原因是因爲你不小心犯了一個巨大的文件,或者是因爲有法律限制,我建議恢復的承諾。這將保留提交但刪除其所有更改。換句話說,提交仍然會在該項目的歷史(沿提交後歸還),但它的變化將會消失。

git revert HEAD  # revert the currently checked out commit 
git revert 123456abc # revert the commit with id 123456abc 
git revert master~ # revert the parent commit of the master branch 

git reset --hard和重寫一個分支的歷史的其它方法是強大的和有用的工具,但它,瞭解它的侷限性和後果,是一個好主意。