git Time Travel

If you want to go “back in time” to a previous commit, copy something, return to your current commit and use the old code: https://stackoverflow.com/a/4114122/5225057

If you want to temporarily go back to it, fool around, then come back to where you are, all you have to do is check out the desired commit:

git checkout <first 7 or 10 letters in the git commit ID>

To go back to where you were, just check out the branch you were on again. i.e.git checkout master

For example, usegit logto see your commit history, find the commit you want to make current, copy it’s commit ID, then usegit checkout <commit ID>to make a temporary branch from the commit. Usegit branch -ato list the branch and note the star next to the “current” branch. In your text editor, you should see the changes have reverted to the old commit. Copy what you need. Then switch back to the master branch withgit checkout master. In your text editor, you should see that the files are back to where you left off.git branch -awill report that you are on “master again” and the temp branch is gone.git logwill also confirm that your latest commit is the current one. You can now paste the code you copied out of the old commit into your current work🙂

results matching ""

    No results matching ""