我无意间把错误的档案 写错给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为了更好地了解它的作用

reflog 格式

如果你搞砸了,你总是可以使用折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式折叠式

$ 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 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 HEAD^

这将带来项目状态 之前,您已经做出承诺。

我通常首先会发现我最近所作所为的杂草:

git log

看起来是这样的:commit {long_hash}

复制此副本long_hash并重置它(回到相同的文件/声明在承诺上):

git reset --hard {insert long_hash without braces}

IntellelliJIDEA 您可以按下打开 Git 的 Git 仓库日志平平+9,鼠标右键单击承诺列表中的某些标记,并选择:重置当前分支到这里....

git reset --soft HEAD~1

git status

Output

在分母上
您的分行在“ 来源/ 主机” 前面 1 个承诺 。
(使用“ little push” 发布您的本地承诺)

拟承诺的修改:
(使用“ git reconful -- paged...” 到 unstage) 新文件 : file1

git log --oneline --graph

Output

  • 90f8bb1 (HEAD - > 主人) 第二次承诺\
  • 7083e29 初始仓库承诺