Say I have a directory containing hundreds of files. I modify several of them, but afterwards I realize my changes are bad. If I do:
git checkout whole_folder
Then everything gets checked out again, and I have to recompile everything. Is there a way to make checkout affect only modified files, or do I need to run checkout
on each file separately?
No, you can't. All these commands deal with committed history.
The git checkout command can be used in a commit, or file level scope. A file level checkout will change the file's contents to those of the specific commit.
Try this:
$ git checkout `git ls-files -m`
-m lists only the modified files.
But
git checkout -- $(git ls-files -m)
also checksout the deleted files.
If you want to checkout only the modified files this work for me:
git checkout -- $(git status -uno | grep --colour=never '#' | awk '{ print $2 $3 }' | grep --colour=never ^modified: | cut -c10-)
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