我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
IntellelliJIDEA 您可以按下打开 Git 的 Git 仓库日志平平+9,鼠标右键单击承诺列表中的某些标记,并选择:重置当前分支到这里....
其他回答
替换索引中的文件 :
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
git reset --soft HEAD~1
或者如果你们记不起来,那末,你们可以使用
git rm --cached <file>
从存储库历史中移除文件的正确方式正在使用git filter-branch
。也就是说,
git filter-branch --index-filter 'git rm --cached <file>' HEAD
但我建议您谨慎使用此命令。 更多信息git-过滤器-分栏(1) 手册.
我更喜欢用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 push --delete (branch_name) //this will be removing the public version of your branch
git push origin (branch_name) //This will add the previous version back
尝试此选项, 硬重置到未添加文件的上一个任务, 然后 :
git reset --hard <commit_hash>
确保您有备份的更改, 以防万一, 因为它是一个困难的重置, 这意味着它们会丢失( 除非您更早隐藏) 。