我认为这是关于 git 的最常见问题。 但我有具体问题。
例如,我在本地 git 中得到了几个文件,并且修改了其中的一些文件。一旦我记忆起我在一个文件中犯了一个错误,但我想保存其余文件中的更改。 我可以通过 git add 将它们的状态更改为暂存,但是如何仅提交选定的文件并返回我现在不想提交的文件的原始版本。
所以,我想,我的问题是如何返回一个文件的未修改版本并保存另一个文件的更改。 谢谢
最佳答案
您可以使用新的 command git restore ( less confusing than git checkout
),使用 Git 2.23+(2019 年 8 月)
You can restore both the index and the working tree (this the same as using
git-checkout
)$ git restore --source=HEAD --staged --worktree hello.c
or the short form which is more practical but less readable:
$ git restore -s@ -SW hello.c
关于git - 当我想获得另一个文件的未修改版本时,如何只提交一些文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58124911/