I have commited some changes from feature branch onto remote master branch and opened pull request. But i have forgot to fix phpcs violations (running code sniffer) for which i need the difference between when there were no changes in a file/commit and changes i made - I need to get back into the point where i was before commiting - to have all the rows changed saying "modified" and i need to do that for 3 commits of that feature branch. Would someone please help me how to achieve that, or how is it called?
CodePudding user response:
Use an interactive rebase to edit/redo all of your commits. You need to follow the procedure mentioned in the splitting commits section in the git rebase
documentation without actually splitting your commits.
Before running this, make sure to have a backup of your branch and a clean working copy (git stash push -u
).
git rebase -i $basecommit
# change "pick" to "edit" for the commits you want to redo
# rebase will stop at first "edit" commit
git reset --soft HEAD^
# run your tool, make necessary changes
# add changes
git commit -C HEAD@{1} # make a new commit reusing message and author from the commit before reset
# resolve potential conflicts
# rinse and repeat
Another option would be to use git cherry-pick
:
git checkout $basecommit^{commit} # go to detached HEAD state
git cherry-pick --no-commit $firstcommit
# run your tool, make necessary changes
# add changes
git commit -C $firstcommit # make new commit reusing message and author from first commit
# repeat for $secondcommit, $thirdcommit, etc.
git checkout -B $yourbranch # label the newly created history with your branch name