我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
取决于您是否已经公开了您的前一次承诺( 插入到您的远程仓库 ) :
比方说我承诺了当地, 但现在我想取消那个承诺。
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 - 撤销事情.
其他回答
作为以下步骤。
步骤1
命中git log
从日志列表中找到最后的硬化散列代码, 然后输入 :
步骤2
git reset <hash code>
单一个命令 :
git reset --soft 'HEAD^'
成功推翻了当地最后的承诺!
我发现这笔该网站描述如何撤销您在存储库中的承诺 。
一些命令 :
git commit --amend # Change last commit
git reset HEAD~1 --soft # Undo last commit
你总是可以做一个git checkout <SHA code>
前一版本的版本, 然后再次承诺使用新代码 。
添加/删除文件, 以便按照您想要的方式获取文件 :
git rm classdir
git add sourcedir
然后修正承诺:
git commit --amend
之前的错误承诺将会被编辑 以反映新的指数状态 换句话说,这就像你从未犯过错误一样
请注意,你只应该在还没有推的时候做这个。如果你已经推了,那么你只需要正常地做一个修正。