我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
你会遇到这个问题:
$ git reset HEAD~
fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
发生错误的原因是,如果最后一次承诺是存储处的初始承诺(或没有父/母),则不存在 HEAD~ 。
如果您想要重置“ master” 分支上唯一的承诺
$ git update-ref -d HEAD
$ git rm --cached -r .
其他回答
取决于您是否已经公开了您的前一次承诺( 插入到您的远程仓库 ) :
比方说我承诺了当地, 但现在我想取消那个承诺。
git log
commit 101: bad commit # Latest commit. This would be called 'HEAD'.
commit 100: good commit # Second to last commit. This is the one we want.
要让一切恢复到上次承诺之前的状态 我们需要reset
之前的承诺HEAD
:
git reset --soft HEAD^ # Use --soft if you want to keep your changes
git reset --hard HEAD^ # Use --hard if you don't care about keeping the changes you made
现在git log
将显示我们最后的承诺已被删除 。
如果您已经公开了承诺, 您将会想要创建一个新的承诺, 它将“ 撤销” 您对上一个承诺( 当前 HEAD) 所做的更改 。
git revert HEAD
你们的更改将恢复,并准备好你们承诺:
git commit -m 'restoring the file I removed by accident'
git log
commit 102: restoring the file I removed by accident
commit 101: removing a file we don't need
commit 100: adding a file that we need
更多信息,请查看Git Basics - 撤销事情.
您可以使用git revert <commit-id>
.
为了得到身份证明 只需使用git log
.
git reset --soft HEAD^
或git reset --soft HEAD~
这将撤销最后一项承诺 。
给--soft
意思是重置为中位 。
HEAD~
或HEAD^
意思是移动以在 HEAD 之前承诺 。
git commit --amend -m "message"
它将以新承诺取代最后一项承诺 。
我发现这笔该网站描述如何撤销您在存储库中的承诺 。
一些命令 :
git commit --amend # Change last commit
git reset HEAD~1 --soft # Undo last commit