gpt4 book ai didi

Git 恢复某些文件

转载 作者:IT王子 更新时间:2023-10-29 01:26:46 28 4
gpt4 key购买 nike

我想恢复提交,但仅限于某些文件。 (不是 checkout ;是还原。如果您不熟悉其中的区别,请继续阅读。)

我试过了

git revert --no-commit abcdef123456 -- my/path/to/revert

我得到了这个错误

fatal: ambiguous argument 'my/path/to/revert': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions

但这正是我所做的! (是的,my/path/to/revert 在我的工作树中。)

我的工作理论是不可能仅恢复某些文件,并且 Git 错误消息具有误导性。

(Git 1.7.9.5)


这不是 Reverting a single file to a previous version in git 的副本

  • 这个问题(尽管有标题)属于 git-checkout。 check out 将文件恢复到以前的版本,删除该点之后的所有提交。
  • 我的问题与 git-revert 有关。还原会撤消在特定提交中所做的更改,而不会触及稍后可能出现的其他提交。它应用(仅)该提交的反向。

最佳答案

我认为 git 不允许您指定要还原的特定文件。我能想到的最好的是:

git revert --no-commit <commit hash> # Revert, don't commit it yet
git reset # Unstage everything
git add yourFilesToRevert # Add the file to revert
git commit -m "commit message"
git reset --hard # Undo changes from the part of the revert that we didn't commit

关于Git 恢复某些文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23068790/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com