git smartgit 删除提交并返回上一次提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32394214/
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
smartgit delete commit and return to previous commit
提问by Lowtrux
By mistake i have made a commit that now i want to delete from the history log and return to a previous commit. I have been trying to checkout the commit that i want to return to but Smartgit ask me to create a local branch in order to do this (screen shot attached) and since im not an expert with SG i really need some advice. I have also try to revert the commit that i made by mistake but i still see the commit on the log. This is how the log look now:
我错误地做了一个提交,现在我想从历史日志中删除并返回到以前的提交。我一直在尝试检查我想返回的提交,但 Smartgit 要求我创建一个本地分支以执行此操作(附上屏幕截图),而且由于我不是 SG 的专家,我真的需要一些建议。我也尝试恢复我错误地提交的提交,但我仍然在日志中看到提交。这是日志现在的样子:
When trying to checkout :
尝试结帐时:
How my log looks at the moment :
我的日志现在的样子:
What i want to do is delete the first two commits from the log and return to the "Cambios Varios" commit (the one with the green arrow that btw appeared when i was trying to check out that commit).
我想要做的是从日志中删除前两个提交并返回到“Cambios Varios”提交(顺便说一下,当我尝试检查该提交时出现的带有绿色箭头的提交)。
All this mess was because my coleague made some changes and add a file and then commit his changes, in order to have my files updated i made a pull but my files didn't get updated on my local repository and didnt add the file that was added by my coleague. Is there something else i have to do in order to update all my folders when another user do a commit besides PULL ? Im pretty new to SmartGit and is kinda of confusing everytime im trying to do a clean pull. Many thanks !
所有这些混乱都是因为我的同事做了一些更改并添加了一个文件,然后提交了他的更改,为了更新我的文件,我进行了拉取,但我的文件没有在本地存储库中更新,也没有添加文件由我的同事添加。除了 PULL 之外,当另一个用户进行提交时,我还需要做些什么来更新我的所有文件夹?我对 SmartGit 很陌生,每次我尝试做一个干净的拉动时都会有点困惑。非常感谢 !
采纳答案by Mikhail
What you are asking is not specific to SmartGit, but to GIT in general. SmartGit is merely a client, though very convenient and fully featured. In your situation you have to take into account several GIT features:
你问的不是 SmartGit 特有的,而是一般的 GIT。SmartGit 只是一个客户端,虽然非常方便且功能齐全。在您的情况下,您必须考虑几个 GIT 功能:
- Branches
- Published commits
- Detached head
- Rewriting remote history
- 分行
- 已发布的提交
- 分离头
- 重写远程历史
Google on these to get additional info. Now, let's give names to your commits:
谷歌这些以获取更多信息。现在,让我们为您的提交命名:
You continue to see commit A
, because you have a branchpointing on it. This is your localbranch master
. You can resetthis branch to whatever commit you like. In SmartGit to do this, just click down on that green branch label and drag it to any other commit. That's it. E.g. reset it to commit B
, where origin/master
is pointing to, and you will no longer see this commit in your log, because there is no branch from which it can be reached.
您继续看到 commit A
,因为您有一个指向它的分支。这是您当地的分支机构master
。您可以将此分支重置为您喜欢的任何提交。要在 SmartGit 中执行此操作,只需单击该绿色分支标签并将其拖动到任何其他提交。就是这样。例如,将其重置为 commit B
,origin/master
指向where ,您将不再在日志中看到此提交,因为没有可以访问它的分支。
Strictly speaking, you may do the same trick with your origin/master
branch, you may reset it to any other commit. But you should be very careful with it, because it points on a commit B
, which is published. I.e. anyone may have it pulled on their machine. If you cannot tell for sure, you cannot reset branch from a published commit without danger of breaking someone's copy of the repo.
严格来说,您可以对您的origin/master
分支执行相同的操作,您可以将其重置为任何其他提交。但是你应该非常小心它,因为它指向一个 commit B
,它被发布。即任何人都可能将它拉到他们的机器上。如果你不能确定,你不能从已发布的提交中重置分支,而不会破坏某人的 repo 副本。
So the simple answer is you cannot revert the repo to the commit C
as you want, because it may conflict with repos cloned on other machines. The longer answer is you can try it.
所以简单的答案是你不能根据需要将 repo 恢复到提交C
,因为它可能与在其他机器上克隆的 repos 冲突。更长的答案是您可以尝试一下。
If you are sure that the only persons that have this repo cloned is you and your colleague, you may rewritethe remote log. For this, reset your local master
branch on commit C
(with drag&drop, as I told earlier) and pushit. SmartGit may forbid you from doing so, go to Preferences/Commands/Push and enable option "Allow modifying pushed commits". Because it is dangerous.
如果您确定唯一克隆了此 repo 的人是您和您的同事,则可以重写远程日志。为此,master
在提交时重置您的本地分支C
(如我之前所说的,通过拖放操作)并推送它。SmartGit 可能会禁止您这样做,请转到首选项/命令/推送并启用选项“允许修改推送提交”。因为它很危险。
This will rewrite position of remote master
branch, pull from it from machine of your colleague. If he did not made any additional changes to this branch, this should be fine.
这将重写远程master
分支的位置,从你同事的机器上拉出来。如果他没有对这个分支做任何额外的改变,这应该没问题。