how can I go back in git to a specific commit, without losing some data later?

2

Hi, I would like to know how I can go back in git to a specific commit, without losing some data later? to restore it it's possible? Thank you very much

    
asked by NEFEGAGO 27.12.2017 в 16:24
source

2 answers

1

Hello after searching and advice I have come to a nice solution:

  • the issue is being in the branch of work to take the name of the commit from which you want to go back and then I use git checkout Ej.: git checkout 0606544 this creates a new branch called > HEAD which will contain regression data. see ( git checkout )

  • At this point we suggest a " git branch" name for branch "" can be done immediately or later

  • Well the interesting part is here where we started to copy the commits that we want to recover for that we use git cherry-pick Example: git cherry-pick 0865866 see ( git-cherry-pick )

  • answered by 27.12.2017 / 22:30
    source
    1

    There are several ways to do that and everything will depend on the particular case, I try to explain different procedures that can be used:

    On the one hand, if we want to return a few files to the way they were before (leaving the changes we made in the rest of the repo), the option is to do:

    git checkout 060654 -- app/ejemplo.js doc/*
    

    This what it does is to return the files (but only those) to a previous version, after that, the necessary changes are made and a commit is made.

    The other option is to undo some commits that were bad (but they are in master), in this case, the command that helps is:

    git revert 819752
    

    This commits it to undo the changes that were wrong, but it maintains the continuity of the story.

    As an alternative, if what you want is to fix changes that are not yet in master, it is best to make a rebase interactive that is more complicated but is super powerful:

    git rebase -i master
    

    This command allows you to fix the history, editing commits, rearranging them, deleting them, etc. In essence what it does is to automate and organize the checkout and cherry-pick process that explains NEFEGAGO .

        
    answered by 24.01.2018 в 18:39