Sometimes, we need to stage everything in our workspace to a Git commit, except one particular file.
To stage everything except a file called
foo.txt, run the following two commands in your terminal:
git add -u git reset foo.txt
Staging all but one folder
A similar approach also works with folders.
Here’s how we could stage everything except a folder called
git add -u git reset -- foo/*
Notice how we insert the “
--” argument and append “
/*” to the folder name.
This lets Git know that we’ve provided a path that leads somewhere, and that we want to exclude everything within the folder.
I wanted to keep this post short and sweet, and I hope you found it useful!
This is the first of countless handy Git snippets that I look forward to sharing on this blog.