Committing
Get Number of Git Commits to Squash
Here's the easiest way to get the number of commits is by running the following:
You can then use that number in your git rebase -i HEAD..n
command. Or if you're feeling adventurous, you can merge the two into a single command that counts and squashes at the same time.
The use of sed
here is to remove the spaces that appear in wc
's output.
Remove All Untrack Files
To remove all untracked files in a particular repository:
Supported flags:
-f
: force-d
: directories too-x
: remove ignored files too
Selectively Apply Changes From Patch
This can be used to select the hunks you want to apply from a patch file.
Apply the patch using
git apply
Enter git add interactive mode using
git add --patch
. This will allow you to select the hunks to apply. See man page.
Once done, changes will be staged but not reflected in the working directory. To apply the staged changes to the working directory:
Stash them using
git stash save --keep-index --include-untracked
Then run
git stash drop
Last updated