我无意中把错误的文件给了Git, 但还没有把承诺推到服务器上。
我如何从当地存储库撤销这些承诺?
我无意中把错误的文件给了Git, 但还没有把承诺推到服务器上。
我如何从当地存储库撤销这些承诺?
当前回答
您可以对上一个版本进行 Git 检出 < SHA code> , 然后再对新代码再次承诺 。
其他回答
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
#1) $ git commit -m "Something terribly misguided"
#2) $ git reset HEAD~
[必要时编辑文件]
#3) $ git add .
#4) $ git commit -c ORIG_HEAD
您可以以两种方式撤销您的 Git 承诺 : 首先, 您可以使用 Git 返回, 如果您想要保留您的承诺历史 :
git revert HEAD~3
git revert <hashcode of commit>
第二是您可以使用 Git 重置, 这将删除您全部的委托历史, 并随心所欲地将您的头移到您想要的地方 。
git reset <hashcode of commit>
git reset HEAD~3
您也可以使用 -- hard 关键词, 如果有的话, 如果它开始有其他行为的话。 但是, 我建议在非常必要的时候使用它。
这里是网站: 哦,该死,混蛋!
这里有许多解密的秘方 如何在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 在另一个位置克隆仓库。 将修改( 文件/ 目录) 从原始仓库复制到这个新的仓库。 然后承诺并按下新仓库的修改。 用这个新的仓库替换旧的仓库 。