I have a large git project that I, stupidly, imported to eclipse and ran an autoformat on. Now, every file in the project is showing as modified. Rather than commit my formatted files, I would rather revert all the files that I have only been formatted and not had other changes. For instance:
$ git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # (commit or discard the untracked or modified content in submodules) # modified: dir/file1.cpp # modified: dir/file1.h # modified: dir/file2.cpp # modified: dir/file2.h # modified: dir/file3.cpp # modified: dir/file3.h # modified: dir/file4.cpp # modified: dir/file4.h I know that file2.cpp, file2.h, and file3.cpp have been modified with content (i.e., not just formatted). I want to stash the changes to these three files and then checkout an old revision, so that I can reapply the changes to these files after. I would rather avoid something like:
$ cp file2.cpp ~/tmp $ git checkout blahblahblah $ cp ~/tmp/file2.cpp . If there's an obvious way to do this that doesnt involve stashing, let me know. whatever gets the job done.
git addthe files with changes you want to keep and thengit checkout -- .and then unstage the added files at the end if you want to.git stash push -- file2.cpp file2.h file3.cpp. See my answer below