0

TL;DR: How to move a folder-specific git history and changes from one branch to another, ignoring all other commits that are not related to that specific folder.


I incorrectly worked on a branch for days, correctly committing the changes related to that branch but also committing changes that should have been in another branch entirely.

Both the "right" commits (the ones that should remain in current branch) and "wrong" commits (the ones that need to be moved to the new branch) are kind of together, so it would be time-consuming to cherry-pick each commit. There's also a lot of them.

Since all the "wrong" changes are in the same folder, and such folder doesn't have any "right" commits, I thought it would be easier to find a way to move a folder-specific git history into another branch.

Is this possible? I failed at googling such solution. Mostly found how to move from repo-to-repo.

Thanks.

1 Answer 1

1

cherry-pick can take a list of commits, so you just have to give the right list of commits.
As you have a criterion (the folder) to select the right commits, it won't be time-consuming:

git rev-list <START_POINT>^..<END_POINT> -- path/to/the/folder 

This will list all the commit SHA1 between START_POINT (included) and END_POINT that modified files inside the folder path/to/the/folder.

Then, to cherry-pick them, just git this list as input of git cherry-pick:

git cherry-pick $(git rev-list <START_POINT>^..<END_POINT> -- path/to/the/folder) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.