Search code examples
gitatlassian-sourcetree

Temporarily revert to previous commit, make changes, keep the changes and come back to latest commit?


As you can tell from the title, the reason I'm needing to make my own question about this is I can't quite get the terminology correct to properly search.

I'm working with Git in Sourcetree, and say I have a history of commits

F <- I am here
E
D
C
B
A

What I need to do is restore the working environment to commit C. Then, make some changes and additions to the code (to export a quick patch for the app being developed) and then to return back to F, preserving the changes I made.

I feel like I need to Checkout C, but am unsure at the moment, and would prefer not to bork everything until I get a better understanding.

Edit: I was thinking I could Checkout C, make changes. Stash the changes. Go back to F. And then apply/commit the stash?


Solution

    1. commit all your current changes in 'F'.

    2. create a branch from 'C': git checkout C -b C-branch.

    3. do whatever you need and commit your changes: git commit

    4. check out 'F' again: git checkout F

    5. merge with the C-branch: git merge C-branch