Ref: https://stackoverflow.com/a/44789323
-
create a new branch
git checkout -b new_clean_branch
-
apply all changes
git merge original_messy_branch
-
forget the commits but have the changes staged for commit
git reset --soft master
git commit -m "Squashed changes from original_messy_branch"
- Cherry pick all the changes from a commit to your target branch -
git cherry-pick -n <commit id>
(-n only stages the commit but do not commit it directly) - Unstage the changes so that you can add them later after filtering desired part. -
git reset
- Add only part of patch -
git add -p
. This will allow you to pick only part of changes you're interested in. - commit your staged changes -
git commit -m "changes"
You can get the commit history for a file in command git log -p -- filepath.ext
. Then grep the line you want to see