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

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


当前回答

如果你有Git 外加已安装, 您可以运行git undo撤消最近的承诺。git undo 3将撤销最后三项承诺。

其他回答

您可以从本地仓库撤销您的承诺 。 请遵循以下方案 。

在下面的图像中, 我检查“ 测试” 分支( 使用 Git 命令)git checkout -b test)作为本地检查状态(使用 Git 命令)git status地方分支中没有任何可承诺的。

Enter image description here

在下一个图像图像中,您可以看到这里的图像 我做了一些修改过滤器1. txt然后用一些信息(使用 Git 命令) 将文件添加到中继区, 并用一些信息( 使用 Git 命令) 来进行更改git commit -m "Doing commit to test revert back").

"-m 用于发送信件"

Enter image description here

在下一个图像中,您可以看到您承诺的日志,无论您承诺什么(使用 Git 命令)git log).

Enter image description here

所以在以上图像中,您可以看到每个承诺的承付代号, 以及您现在的执信信息, 无论您想要返回或撤消的复制件, 即实施 ID 并击中下面的 Git 命令,git revert {"paste your commit id"}示例:

git revert 9ca304ed12b991f8251496b4ea452857b34353e7

Enter image description here

我恢复了上次的承诺。 现在, 如果您检查您的 Git 状态, 您可以看到修改后的文件过滤器1. txt并且尚未承诺。

Enter image description here

git reset --soft HEAD~1

重置将会将您当前的 HEAD 分支倒带到指定的修订版 。

Note--soft旗帜 : 这样可以确保未撤销修改中的更改被保存。 在运行命令后, 您会发现这些更改是您工作副本中未承诺的本地修改 。

如果您不想保留这些修改,只需使用--hard。确保只在确定不再需要这些更改时才这样做。

 git reset --hard HEAD~1

撤消多个提交文件

git reset --hard 0ad5a7a6

但是,记住,使用重置命令可以解除所有在你返回后的承诺:

Enter image description here

如果您想要撤销在回邮中的第一个承诺

你会遇到这个问题:

$ git reset HEAD~
fatal: ambiguous argument 'HEAD~': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

发生错误的原因是,如果最后一次承诺是存储处的初始承诺(或没有父/母),则不存在 HEAD~ 。

解决方案

如果您想要重置“ master” 分支上唯一的承诺

$ git update-ref -d HEAD
$ git rm --cached -r .

使用使用git revert <commit-id>.

要拿到身份证明,请使用git log.

取决于您是否已经公开了您的前一次承诺( 插入到您的远程仓库 ) :

如何撤销本地任务

比方说我承诺了当地, 但现在我想取消那个承诺。

git log
    commit 101: bad commit    # Latest commit. This would be called 'HEAD'.
    commit 100: good commit   # Second to last commit. This is the one we want.

要让一切恢复到上次承诺之前的状态 我们需要reset之前的承诺HEAD:

git reset --soft HEAD^     # Use --soft if you want to keep your changes
git reset --hard HEAD^     # Use --hard if you don't care about keeping the changes you made

现在git log将显示我们最后的承诺已被删除 。

如何撤销公开承诺

如果您已经公开了承诺, 您将会想要创建一个新的承诺, 它将“ 撤销” 您对上一个承诺( 当前 HEAD) 所做的更改 。

git revert HEAD

你们的更改将恢复,并准备好你们承诺:

git commit -m 'restoring the file I removed by accident'
git log
    commit 102: restoring the file I removed by accident
    commit 101: removing a file we don't need
    commit 100: adding a file that we need

更多信息,请查看Git Basics - 撤销事情.