Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Checkout all files except one

When I do a git status, I see files like this:

modified:  dir/A/file.txt modified:  dir/B/file.txt modified:  dir/C/file.txt modified:  dir/D/file.txt 

What I want to do is to discard changes to all files EXCEPT for dir/C/file.txt

I want to do something like this:

git checkout -- dir/!C/file.txt 
like image 648
Kyle Avatar asked Nov 15 '13 18:11

Kyle


People also ask

How do I add all files except one in git add?

Run a 'git add . ' to add all the files. Then run 'git reset -- xxx/dontcheckmein. txt'.

How to Exclude file in git commit?

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.

What is git checkout --?

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.


1 Answers

git add dir/C/file.txt # this file will stay modified and staged git checkout . 

If you want to unstage the file after that:

git reset 
like image 124
mechanicalfish Avatar answered Sep 28 '22 04:09

mechanicalfish