我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。
我如何解除那些承诺?当地当地仓库?
当前回答
您可以使用git reset unwanted_file
命令您不想进入阶段的文件 。 通过使用此命令, 我们可以将更改的文件从中继区域移到工作目录 。
其他回答
撤销最后一次承诺的最简单方式是
git reset HEAD^
这将带来项目状态 之前,您已经做出承诺。
假设您在本地犯下错误, 并将其推到远程仓库。 您可以解开这两个命令的混乱 :
首先,我们需要纠正我们的地方储存库,回到我们所希望的承诺上来:
git reset --hard <previous good commit id where you want the local repository to go>
现在,我们通过使用此命令,在远程仓库大力推动这项良好承诺:
git push --force-with-lease
强制选项的“ 租赁” 版本将防止意外删除您不知道的新承诺( 即上次拉动后来自其它来源 ) 。
我验证了所提议的有效方法,这里就是使用这一方法的一个具体例子:
如果您想要永久撤销/取消您的最后一项承诺(等等, 一个一个一个, 尽可能多) , 有三个步骤 :
1: 获取您想要到达的承诺的 id = SHA, 当然
$ git log
2: 删除您先前的承诺
$ git reset --hard 'your SHA'
3: 将新的本地历史强制在您的原籍 GitHub 与-f
选项( 将从 GitHub 历史中删除最后的磁轨)
$ git push origin master -f
$ git log
最后一次承诺取消
commit e305d21bdcdc51d623faec631ced72645cca9131 (HEAD -> master, origin/master, origin/HEAD)
Author: Christophe <blabla@bla.com>
Date: Thu Jul 30 03:42:26 2020 +0200
U2_30 S45; updating files package.json & yarn.lock for GitHub Web Page from docs/CV_Portfolio...
现在就向总部提交我们想要的文件
commit 36212a48b0123456789e01a6c174103be9a11e61
Author: Christophe <blabla@bla.com>
Date: Thu Jul 30 02:38:01 2020 +0200
First commit, new title
$ git reset --hard 36212a4
HEAD is now at 36212a4 First commit, new title
$ git log
commit 36212a48b0123456789e01a6c174103be9a11e61 (HEAD -> master)
Author: Christophe <blabla@bla.com>
Date: Thu Jul 30 02:38:01 2020 +0200
First commit, new title
$ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
(use "git pull" to update your local branch)
nothing to commit, working tree clean
$ git push origin master -f
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To https://github.com/ GitUser bla bla/React-Apps.git
+ e305d21...36212a4 master -> master (forced update)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
通过下列方式查看日志来查找上次承诺的散列代码 :
git log
然后
git reset <the previous co>