How do I revert back to earlier commit using source tree

32,600

Solution 1

Temporary Revert Back

If you want to temporarily go back to this commit, then come back to where you are.

Right click on the commit you want to revert to and click on "checkout".

Permanent Revert Back

This will add commits to revert all your work since this commit

Right click on the commit you want to revert to and click on "Reset <> to this commit".

enter image description here

Solution 2

I think in above discussion @dominones and @Giraldi maybe misunderstand each other,

@Giraldi maybe want to delete those unwanted commits permanently in the GIT, and make the git go back to a certain history commit, from there he could start all over again, like you want to be fresh from the beginning of somewhere.

while @dmonones is showing just how to revert back to a status of your code in a history, discarding some code changes you did, which will mostly end up with a new commit aiming to remove a unwanted/mistaken change, without changing the git history.

To discard an already committed commit in git history, you need to use hard reset and push with force.

Share:
32,600
burrGGG
Author by

burrGGG

Updated on October 10, 2020

Comments

  • burrGGG
    burrGGG over 3 years

    I have a project stored on my Mac and created a repository for from that location to my project. I am able to commit using source tree but now I would like to revert back to an earlier commit so all my files in folder update? I'm not sure how i do this?

  • dminones
    dminones over 9 years
    @Chris edited to add more detail to "temporary" and "permanent".
  • Giraldi
    Giraldi over 7 years
    Doing the "Permanent Revert Back" will have the later commits in the "Pull" queue. So if I do a pull, those commits will return. How do I avoid this?
  • dminones
    dminones over 7 years
    @Giraldi since those in the pull queue would be new commits is ok that they stay after the rever, if you also want to undo commits that you didn't pulled yet you should first pull and then revert.
  • Giraldi
    Giraldi over 7 years
    @dminones Sorry.. I don't really understand what you mean. Can describe in more detail how I can avoid re-pulling unwanted commits?
  • dminones
    dminones over 7 years
    @Giraldi if you already pulled your unwanted commits will not be "re-pulled" since the permanent revert back adds commits with inverse changes forward in the timeline .The result is that after you revert you will not have this unwanted changes in the "pull queue"
  • Giraldi
    Giraldi over 7 years
    @dminones Yes, I was hoping that is the case, but unfortunately those unwanted changes IS in the pull queue. Any settings I missed? 'Cause I'm sure I followed the exact procedure.
  • Adam B
    Adam B almost 5 years
    @Giraldi Any solution on that?
  • Giraldi
    Giraldi almost 5 years
    @AdamB Not really, but I'd probably use the Temporary Revert Back and force push it to master, or whatever branch I'm trying to revert.
  • Miksmith
    Miksmith almost 4 years
    If you checkout to get back to that particular commit locally, how then do you revert back to where you were before the commit?
  • Ciabaros
    Ciabaros over 3 years
    In the first section of your answer, you say "If you want to do A, then B" and then proceed to only provide a step for A. You should add: "Now, to switch back to your original (latest) commit, just check out that latest commit." It's obvious for seasoned users, but it's scary for those who hadn't done it, with all the detached head warnings..