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

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


当前回答

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

在下面的图像中, 我检查“ 测试” 分支( 使用 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

其他回答

enter image description here

假设您在视觉工作室工作, 如果您进入分支历史, 并查看您的所有承诺, 只需在承诺之前选择事件, 您想要撤销, 右单击它, 然后选择Revert轻而易举

我想撤销我们共享存储库中最新的五个承诺。 我查了我想回溯到的订正代号 。 然后我输入了下面的内容 。

prompt> git reset --hard 5a7404742c85
HEAD is now at 5a74047 Added one more page to catalogue
prompt> git push origin master --force
Total 0 (delta 0), reused 0 (delta 0)
remote: bb/acl: neoneye is allowed. accepted payload.
To git@bitbucket.org:thecompany/prometheus.git
 + 09a6480...5a74047 master -> master (forced update)
prompt>

你需要做简单快的动作

    git commit --amend

是私人分行还是私人分行

    git commit -m 'Replace .class files with .java files'

如果它是共享的或公共的分支。

$ git commit -m 'Initial commit'
$ git add forgotten_file
$ git commit --amend

重要的是要明白,当你正在修正你的最后一项承诺时,你并没有完全用新的、更好的承诺来取代它,新的承诺将旧承诺推开,而将新承诺置于其位置。 事实上,这好像前一项承诺从未发生,也不会出现在你的存储库历史中。

修改承诺的明显价值是略微改进你的最后一项承诺,而不会用表格“Oops,忘记添加文件”或“Darn,在最后一项承诺中确定打字符”等字词来模糊你的存储库历史。

2.4 Git Basics - 撤销事情

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

如何撤销本地任务

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

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 - 撤销事情.