我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
我更喜欢用git rebase -i
对于这份工作来说, 因为一份不错的清单 出现在我可以选择摆脱承诺的地方。 它可能不如这里的其他答案直接直接, 但是它只是...感觉右右.
选择要列出多少个承诺, 然后这样引用( 加入最后 3 个)
git rebase -i HEAD~3
样本列表
pick aa28ba7 Sanity check for RtmpSrv port
pick c26c541 RtmpSrv version option
pick 58d6909 Better URL decoding support
然后 Git 将删除任何您删除的线条 。
其他回答
为了完整起见,我将提出前几个答复所忽略的一个明显明显的方法。
由于承诺没有被推,遥控器没有改变,因此:
有时候,如果你的高贵的Git客户告别(看着你,伊吉特),这有时是必要的。
别忘了重新承诺保存已保存上次按键后的变化 。
认为我们有code.txt 代码转换器。我们对其文件进行一些修改并做出承诺。我们可以以三种方式撤销这一承诺,但首先你应该知道什么是阶段文件...git status
此文件将以绿色颜色显示, 如果此文件没有被预设用于承诺, 则会以红色显示 :
意思是,如果您进行更改,此文件中的更改就不会保存。 您可以在您的舞台上添加此文件git add code.txt
然后承诺更改:
撤消上次承诺 :
你需要做简单快的动作
git commit --amend
是私人分行还是私人分行
git commit -m 'Replace .class files with .java files'
如果它是共享的或公共的分支。
取决于您是否已经公开了您的前一次承诺( 插入到您的远程仓库 ) :
比方说我承诺了当地, 但现在我想取消那个承诺。
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 rm --cached *.class
git add *.java
那么,如果它是私人分支,修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正修正承诺:
git commit --amend
或者,如果它是共享分支, 做出新的承诺:
git commit -m 'Replace .class files with .java files'
(更改上一个承诺,使用真棒交互式重新基数.)
ProTipTM: 添加*.class
至 a高光度( gitignore)阻止这种情况再次发生。
修改承诺是理想的解决办法,如果需要改变最后的承诺,但更普遍的解决办法是:reset
.
您可以将 Git 重置为任何承诺 :
git reset @~N
何处处N
之前承诺的数HEAD
, 和@~
重发到上一个任务 。
您不必修改承诺,而是可以使用:
git reset @~
git add *.java
git commit -m "Add .java files"
退 退 退git help reset
,特别是:--soft
--mixed
和--hard
为了更好地了解它的作用
如果你搞砸了,你总是可以使用折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式
$ git reset @~
$ git reflog
c4f708b HEAD@{0}: reset: moving to @~
2c52489 HEAD@{1}: commit: added some .class files
$ git reset 2c52489
... and you're back where you started