Which git feature should I use for breaking big commit (pushed and reversed) into smaller commits?

70 views Asked by At

I use Atlassian SourceTree to work with git repository.

I committed and pushed big commit where desired and undesired changes were mixed. I rolled it back by committing and pushing Reverse Commit.

Now I want to extract desired changes from that big commit and commit them as smaller commit or may be even sequence of smaller commits.

Which SourceTree or git feature is best for this ? I guess it would be one of these: Cherry-pick, Patch, Merge or Reverse Commit of Reverse Commit with one of these 3 features.

I looked at Break a previous commit into multiple commits and Git Cherry-pick vs Merge Workflow, they are close, but don't directly answer my question.

1

There are 1 answers

0
Andreas Wederbrand On BEST ANSWER

First git cherry-pick -n your original commit using -n for no commit. This will get you all the changes in your working directory but nothing added to the index nor committed.

Then either git add each file that you intend to commit, optionally git add -i or git add -p to select files/patches to add.

Commit whatever you have choose to commit in one commit, and then repeat until all changes are in the desired commits.