我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
使用此命令 :
git checkout -b old-state number_commit
其他回答
单一个命令 :
git reset --soft 'HEAD^'
成功推翻了当地最后的承诺!
替换索引中的文件 :
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 0d1d7fc32
以下是网站: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 :)
先决条件:当修改您存储库中的现有文件时,该修改最初被视为未阶段。为了实施修改,需要分阶段进行,这意味着使用索引
git add
。在一次任务操作中,被筛选的文件会被添加到索引中。
让我们举一个例子:
- A - B - C (master)
HEAD
点点到C
与索引匹配C
.
git reset --soft B
有意并打算删除承诺 C和将主控/ HEAD 指向 B. git status
您可以看到索引中的文件承诺 C计为阶段d. git commit
到此点将创建新承诺与C相同的变化git reset --mixed B
. git add
然后如往常地实践。git reset --hard B
希望这种对可供使用的旗帜的比较git reset
命令会帮助某人明智地使用它们。请参考这些以获取更多细节链接1 & 链接2