我有一个大型 git 项目,我愚蠢地将其导入到 eclipse 并运行自动格式。现在,项目中的每个文件都显示为已修改。我宁愿还原所有仅格式化且未进行其他更改的文件,而不是提交格式化的文件。例如:
$ 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
我知道file2.cpp
, file2.h
, and file3.cpp
已修改内容(即,不仅仅是格式化)。我想存储对这三个文件的更改,然后签出旧版本,以便之后可以重新应用对这些文件的更改。我宁愿避免类似的事情:
$ cp file2.cpp ~/tmp
$ git checkout blahblahblah
$ cp ~/tmp/file2.cpp .
如果有一种不涉及隐藏的明显方法可以做到这一点,请告诉我。无论如何完成工作。
You can add
包含您想要保留的更改的文件,然后stash
其余文件并清除存储:
git add file2.cpp file2.h file3.cpp
git stash --keep-index
此时,您已经隐藏了不需要的更改。如果您想永久摆脱它们,请运行:
git stash drop
现在你有file2.cpp
, file2.h
, and file3.cpp
已准备好提交。如果您想隐藏这些文件(而不是提交它们):
git reset
git stash
现在您将处于之前的提交状态,仅隐藏这三个文件。
Update:
Git 2.13 及更高版本包含一种更直接的方法来存储特定文件git stash push
, 正如 VonC 在他的回答中解释的那样 https://stackoverflow.com/a/42963606/506338.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)