Some of my favorites are: git add -p * This will go through your unstaged changes in chunks and allow you to stage each chunk individually in an interactive shell. git checkout -p * Similar to the...
Some of my favorites are:
git add -p *
This will go through your unstaged changes in chunks and allow you to stage each chunk individually in an interactive shell.
git checkout -p *
Similar to the above, this will go through your unstaged changes and allow you to undo each chunk. I almost never use Ctrl+Z anymore and go straight for this. Want to remove all of those print-debugging statements? Use this command to pluck them out one-by-one.
git commit -a --amend --no-edit && git push --force-with-lease
I alias this one to whoops
in my bash profile. It will add all unstaged changes, add them to your last commit and then (safely) force-push the local branch to the tracked remote branch. This is especially useful when working with CI and you need to make constant configuration changes to get it to work. Yes, you could squash those commits afterwards as an alternative. But this is easier.
git rebase -i HEAD~5
(Change 5
to the number of previous commits you want to see)
Interactive rebases are a core part of my git flow when working on feature branches. If a co-worker gives me feedback on a code review that requires a change to a previous commit I'll go back and edit that commit using this command. You can remove individual commits, squash commits, reorder commits, and so much more.