git Tortoisegit 撤消最后一次提交到 repo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19135403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:04:57  来源:igfitidea点击:

Tortoisegit undo last commit into the repo

gitgithubtortoisegit

提问by user2742122

Is there an option in tortoisegit to undo the last commit into the repo?

tortoisegit 中是否有选项可以撤消对 repo 的最后一次提交?

By mistake I pushed a large number of unnecessary files into my git repository(branch:master) which I need to undo. I have searched a lot for the right option in tortoise git to undo the push and go back to the state before the last commit. Please show me a way to undo my last commit.

我错误地将大量不必要的文件推送到我需要撤消的 git 存储库(分支:主)中。我在 tortoise git 中搜索了很多正确的选项来撤消推送并回到上次提交之前的状态。请告诉我一种撤消上次提交的方法。

采纳答案by Endre Simo

If you need to revert back to the previous state before the last commit just select the commited action from the log list and select revert changes by this commit.

如果您需要恢复到上次提交之前的先前状态,只需从日志列表中选择已提交的操作并选择revert changes by this commit

Take care, you need to commitand pushagain the changes made.

小心,你需要commitpush再次所做的更改。

回答by rustyx

If you haven't pushed your changes yet (so your commit is only local)

如果你还没有推送你的更改(所以你的提交只是本地的)

  1. TortoiseGit-> Show log
  2. Select the commit to which you want to rollback to
  3. Reset "<branch>" to this...
  1. TortoiseGit-> Show log
  2. 选择要回滚到的提交
  3. Reset "<branch>" to this...

If you have, then this can still be done, but then you'd have to also do a force-push(check "overwrite known changes" 1).

如果您有,那么这仍然可以完成,但是您还必须执行强制推送(检查“覆盖已知更改1)。

1The "overwrite known changes" flag will replace the already pushed commit with a new one. If there is a chance that someone already fetched the commit that you're replacing, don't use this feature, otherwise doing so will create a fork in the history with two conflicting truths.

1 覆盖已知更改”标志将用新提交替换已经推送的提交。如果有人已经获取了您要替换的提交,请不要​​使用此功能,否则会在历史记录中创建一个具有两个相互冲突事实的分叉。



There is also a shortcutfor when you want to just (1) redo the last commitand (2) you haven't pushed it yet:

当您只想 (1)重做最后一次提交和 (2) 您还没有推送它时,还有一个快捷方式

  1. Commit -> Check "Amend Last Commit"
  1. 提交 -> 勾选“修改上次提交

That will replace the last commit with a new one. But I don't recommend using this - if the last commit is already pushed, you can end up with a big mess. TortoiseGit will notstop you here.

这将用新提交替换最后一次提交。但我不建议使用它 - 如果最后一次提交已经被推送,你最终可能会陷入一片混乱。TortoiseGit不会在这里阻止你。

By doing a Resetyou are forced to have a look at the log, and there you see if the commit is local or not.

通过执行重置,您被迫查看日志,并在那里查看提交是否是本地的。