Sometimes I find myself in the position where I want to dump everything in my working tree except for 1 or 2 files. Is there an easy way to do this? As it is I've been manually typing git checkout .... for all the files I want to checkout from the index and don't include the files I want to keep but that's pretty laborious.
Another way I could think of doing this would be to stash 1 or 2 files I want to keep, then "checkout ." then restore the stash. Would that be a good way to do this?
Set “–assume-unchanged” to a path to exclude to check on git commit and it will exclude your file from git commit. You will need to use the git update-index and –assume-unchanged to exclude files from git commit.
The git checkout command lets you navigate between the branches created by git branch . Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch.
Short Answergit checkout origin/master -- path/to/file // git checkout <local repo name (default is origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (origin/master).
I want to do the same occasionally and usually go with the following set of commands (assumes than there is nothing in the index):
git add file-to-preserve-1 file-to-preserve-2
git stash save --keep-index "Changes discarded because ..."
# git stash drop # think twice before running this command
git reset
In words:
Another way I can think of (didn't try it actually, the first one works fine for me):
git update-index --skip-worktree file-to-preserve-1 file-to-preserve-2
git checkout .
git update-index --no-skip-worktree file-to-preserve-1 file-to-preserve-2
Explained:
1
as usual again.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With