smartgit delete commit and return to previous commit

后端 未结 2 904
天命终不由人
天命终不由人 2021-01-02 02:54

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 retu

相关标签:
2条回答
  • 2021-01-02 03:22

    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.

    0 讨论(0)
  • 2021-01-02 03:26

    TLDR: Here is a screenshot of it

    0 讨论(0)
提交回复
热议问题