我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
我通常首先会发现我最近所作所为的杂草:
git log
看起来是这样的:commit {long_hash}
复制此副本long_hash
并重置它(回到相同的文件/声明在承诺上):
git reset --hard {insert long_hash without braces}
其他回答
使用此命令
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 reset --soft HEAD^ or git reset --soft HEAD~
这将撤销最后一项承诺 。
给--soft
意思是重置为中位 。
HEAD~ or HEAD^
意思是移动以在 HEAD 之前承诺 。
替换上次承诺的新承诺:
git commit --amend -m "message"
它将以新承诺取代最后一项承诺 。
撤销一项承诺是有点吓人,如果你不知道它是如何运作的。 但如果你理解的话,它其实很容易。我会告诉你4种不同的方式, 你可以解除一项承诺。
说你们有这个,C是你们的总部,(F)是你们档案的状态。
(F)
A-B-C
↑
master
git reset --hard
您想要销毁C国罪行,并抛弃任何未承诺的变更。你这样做:
git reset --hard HEAD~1
结果是:
(F)
A-B
↑
master
现在B是总部,因为你用了--hard
中,您的文件在承诺 B 时被重置为状态。
git reset
也许C不是灾难,只是有点不对劲取消承诺,但保留您的更改在您做更好的承诺之前需要编辑一点。 从这里重新开始, C 做为您的总部 :
(F)
A-B-C
↑
master
做这个,离开--hard
:
git reset HEAD~1
在这种情况下,结果是:
(F)
A-B-C
↑
master
在这两种情况下,HEAD都只是最新承诺的指针。git reset HEAD~1
,您告诉 Git 将 HEAD 指针移回一个承诺。但(除非您使用)--hard
你把你的档案和以前一样留在原样,所以现在git status
显示您在 C 中检查过的更改。 您没有丢失任何东西 !
git reset --soft
最轻轻的触碰,你甚至可以取消您的承诺, 但要离开您的文件和文件指数指数指数指数:
git reset --soft HEAD~1
这不仅留下你的档案, 甚至离开你的指数指数指数指数当你独自一个人去的时候,git status
,你会看到相同的文件在索引中和以前一样。事实上,在这个命令之后,你可以做git commit
你会重蹈覆辙 做你刚做过的同样的事
git reset --hard
需要把密码拿回来还有一件事: 假设你销毁如在第一个示例中,但后来发现你需要它运气不好,对不对?
不,有仍为键入此
git reflog
你将看到一份(部分)承诺的清单,沙沙即你们所迁居的地方。你们要找出你们所摧毁的罪状,然后你们要这样做:
git checkout -b someNewBranchName shaYouDestroyed
承诺在Git不会在90天内被摧毁 所以你通常可以回去 拯救一个你本不想除掉的人
reset --soft
或reset --hard
?@Kyralessa的回答:
如果您不确定该使用什么--soft
(我用这个公约来纪念它)s. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
如果您选择了--hard
你会犯错,你会犯错输 输之前没有的更改。如果您选择--soft
犯错后,您也可以得出相同的结果。--hard
通过应用附加命令
git reset HEAD file.html
git checkout -- file.html
echo "some changes..." > file.html
git add file.html
git commit -m "wrong commit"
# I need to reset
git reset --hard HEAD~1 (cancel changes)
# OR
git reset --soft HEAD~1 # Back to staging
git reset HEAD file.html # back to working directory
git checkout -- file.html # cancel changes
感谢@Kyralessa。