我无意间把错误的档案 写错给Git 基特,但还没有将承诺推进到服务器上。

我如何解除那些承诺?当地当地仓库?


当前回答

如果存储库是在当地承诺的,但尚未被推到服务器上,那么另一种粗糙/佣人解决它的方法将是:

  1. Git 复制另一个位置的仓库 。
  2. 将修改( 文件/ 目录) 从原始仓库复制到此新仓库。 然后承诺并按下新仓库的修改 。
  3. 将旧仓库替换为此新仓库 。

其他回答

要重置上一个修订版, 请永久删除所有未承诺的更改 :

git reset --hard HEAD~1

我验证了所提议的有效方法,这里就是使用这一方法的一个具体例子:

如果您想要永久撤销/取消您的最后一项承诺(等等, 一个一个一个, 尽可能多) , 有三个步骤 :

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 (Hub) 上的历史

$ 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

为了撤销最后的本地承诺, 在不丢弃其改变的情况下, 我有一个便用的别名~/.gitconfig

[alias]
  undo = reset --soft HEAD^

然后,我简单地使用git undo这是超容易记住的。

您可以使用git reset unwanted_file命令您不想进入阶段的文件 。 通过使用此命令, 我们可以将更改的文件从中继区域移到工作目录 。

我如何在本地及远程解析 Git 承诺?

在视觉工作室中,只需返回您的承诺, 然后将它与自动创建的返回承诺一起推。 全部显示在下面的屏幕镜头中 。 @ info: status

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here