2

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?

yesbutmaybeno
  • 1,078
  • 13
  • 31
  • 3
    You want to do an interactive rebase. You'll find plenty of answers on here using that as a search term. – Calum Halpin Oct 02 '19 at 21:10
  • 3
    Possible duplicate of [How can I easily fixup a past commit?](https://stackoverflow.com/questions/3103589/how-can-i-easily-fixup-a-past-commit) – mkrieger1 Oct 02 '19 at 22:37

1 Answers1

2
  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

Serge
  • 11,616
  • 3
  • 18
  • 28