smartgit删除提交并返回到先前的提交 [英] smartgit delete commit and return to previous commit

查看:2060
本文介绍了smartgit删除提交并返回到先前的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我错误地做了一个提交,现在我想从历史日志中删除并返回到前一个提交。我一直试图检查我想要返回的提交,但Smartgit要求我创建一个本地分支以便执行此操作(附带屏幕截图),因为我不是SG的专家,所以我真的需要一些建议。我也尝试恢复我犯的错误,但我仍然看到日志上的提交。这就是日志现在的样子:



尝试结帐时:



现在我的日志是怎样的:





你继续看到commit A ,因为你有一个分支指向它。这是你的本地分支 master 。您可以将此分支重置为您喜欢的任何提交。在SmartGit中,只需点击该绿色分支标签并将其拖到任何其他提交。而已。例如。将它重置为提交 B ,其中 origin / master 指向,并且您将不再在您的日志,因为没有可以到达的分支。



严格地说,你可以用你的 origin / master 分支,您可以将其重置为任何其他提交。但是你应该非常小心,因为它指向 B ,这是发布。即任何人都可能把它拉到他们的机器上。如果您无法确定,则无法重新设置已发布的提交中的分支,而不会破坏某人的回购副本。



所以简单的答案是您无法恢复回购提交给 C ,因为它可能与在其他机器上克隆的repos冲突。如果你确信克隆的这个repo的唯一人员是你和你的同事,你可以重写

/ em>远程日志。为此,请在提交 C 时重置本地 master 分支(如前所述,使用拖放操作)和<推动它。 SmartGit可能会禁止您这样做,请转到首选项/命令/推送并启用选项允许修改推送提交。因为它是危险的。

这会重写远程 master 分支的位置,从同事的机器上拉它。如果他没有对这个分支做任何额外的修改,这应该没问题。

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:

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).

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 !

解决方案

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:

  1. Branches
  2. Published commits
  3. Detached head
  4. 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 branch pointing on it. This is your local branch master. You can reset this 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.

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.

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.

If you are sure that the only persons that have this repo cloned is you and your colleague, you may rewrite the remote log. For this, reset your local master branch on commit C (with drag&drop, as I told earlier) and push it. SmartGit may forbid you from doing so, go to Preferences/Commands/Push and enable option "Allow modifying pushed commits". Because it is dangerous.

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.

这篇关于smartgit删除提交并返回到先前的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆