Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I do and interactive git amend?

How can I undo parts of the last commit, while selecting which parts using an interactive patch mode?
This would come in useful when you’ve accidentally checked in a few lines too many in your last commit, e.g. debug print statements or whitespace changes that your editor did for you.

The naive approach is

git commit --amend --interactive --patch

but this does not seem to work. i.e. it just drops you into an editor to do a rewording.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The ugly approach is

git show HEAD~1:path/to/some/file > path/to-some/file
git add -up
git commit --amend

but this is annoying because it makes you specify the file beforehand, and makes you re-add all patches one by one (rather than allowing you to un-add only bits and pieces)

>Solution :

What about

git reset -p HEAD~
git commit --amend --no-edit

First command will allow you to unstage chunks interactively (select y for the parts you want to get out of the commit), then the commit amend will write that into the new commit.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading