问题描述
我想恢复提交,但仅限于某些文件。 (不是结账;还原。)如果您不熟悉这种差异,请继续阅读。)
我试过这个
git revert --no-commit abcdef123456 - my / path / to / revert
我得到这个错误
致命:ambiguous argument'my / path / to / revert':未知版本或路径不在工作树中。
使用' - '来分隔修订版本的路径
但是,这正是我所做的! (是的, my / path / to / revert
位于我的工作树中。)我的工作理论是(Git 1.7.9.5)
$
$ b
(git 1.7.9.5)
b $ b 这不是。
可以做一个你想要的短列表:
git revert that_commit#做整个还原
git reset - 硬HEAD ^#事实证明是一次性提交
git checkout HEAD @ {1} - 一个/文件夹#只需要你想要的结果
I want to do a revert of a commit, but only for some files. (Not a checkout; a revert. If you are unfamiliar with the difference, keep reading.)
I tried this
git revert --no-commit abcdef123456 -- my/path/to/revert
And I got this error
fatal: ambiguous argument 'my/path/to/revert': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
But that is precisely what I did! (And yes, my/path/to/revert
is in my working tree.)
My working theory is that it is not possible to revert only some files, and that the Git error message is misleading.
(Git 1.7.9.5)
This is not a duplicate of Reverting a single file to a previous version in git.
- That question (despite the title) pertains to git-checkout. A checkout restores a file to a previous version, removing all commits after that point.
- My question pertains to git-revert. A revert undoes changes made in a particular commit, without touching other commits that may have come later. It applies the reverse of (only) that commit.
A shorter sequence for when you can make a short list of what you want:
git revert that_commit # do the whole revert
git reset --hard HEAD^ # in what turns out to have been a throwaway commit
git checkout HEAD@{1} -- one/folder # and just take what you want of the results
这篇关于Git恢复某些文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!