gpt4 book ai didi

git - 是否可以在提交上执行 git revert,但只能在特定目录中执行?

转载 作者:行者123 更新时间:2023-12-02 19:50:04 24 4
gpt4 key购买 nike

正如标题中提到的,我想对进行了一些不需要的更改的提交执行 git revert,但仅限于某个文件夹/目录。

最佳答案

使用 Git 2.23(2019 年 8 月)和 new command git restore ,加上: pathspec signature :

git restore -s@~ -SW -- :path/to/folder/**

长格式:

git restore --source @~ --staged --worktree -- :path/to/folder/**

使用git status检查结果,然后提交。


OP 补充道:

I will need to do a git reset of the files I do not want to keep changes of, before doing git checkout on them.
Doing only git checkout does not work because after git revert, the modified files are in the staging directory.

是的,这就是为什么 git checkout is confusing ,并且正在被替换为:

不需要恢复+重置+ checkout :如果你想恢复文件...使用git恢复

关于git - 是否可以在提交上执行 git revert,但只能在特定目录中执行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58333827/

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