我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
使用使用源树树(Git 的图形工具) 查看您的承诺和树。 您可以单击右键手动重置它 。
其他回答
替换索引中的文件 :
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 checkout -b old-state number_commit
#1) $ git commit -m "Something terribly misguided"
#2) $ git reset HEAD~
[必要时编辑文件]
#3) $ git add .
#4) $ git commit -c ORIG_HEAD
以下是网站:Oh shit, git!
.
这里有许多解密的秘方 如何在Git 中解决事情。其中一些是:
哦,该死,我需要改变 信息在我的最后一次承诺!
git commit --amend
# follow prompts to change the commit message
哦,我无意中把什么东西 给了主人 本来该在全新的树枝上!
# Create a new branch from the current state of master
git branch some-new-branch-name
# Remove the commit from the master branch
git reset HEAD~ --hard
git checkout some-new-branch-name
# Your commit lives in this branch now :)
使用此命令( 在顶部的日志 1 中, 这是最新命令) 获取上次的 身份确认 :
git log
获取执行 ID (GUID) 并运行此命令 :
git revert <commit_id>