3

Is it possible to take the following setup and effectively split a branch into two branches based at a commit history?

eg: start with the following branch and commit history:

branch 1

git log:
commit 1
commit 2
commit 3
commit 4

Create branch 2 at commit 3's id and alter things to the following:

branch 1

git log:
commit 1
commit 2

branch 2
git log: 
commit 1
commit 2
commit 3
commit 4

Use case: I started a new feature on an existing branch not yet in master and committed a bunch of work to that branch. I want to branch off of the last commit before my work and take my work with me and leave that branch clean of all my work.

JDillon522
  • 19,046
  • 15
  • 47
  • 81

1 Answers1

3

You can do a git checkout some_commit_sha to go to a specific commit, and git checkout -b some_branch_name to create a branch from a commit and go to that branch.

Putting the two of those together, you can do git checkout -b some_branch commit_2_sha

Grexis
  • 1,502
  • 12
  • 15
  • Thats what I was thinking, but is there a command that will do that and revert the changes to that commit? Im wagering no, but I thought I'd ask. – JDillon522 Apr 14 '17 at 18:47