[英]How to revert a commit but to a specific folder?
I've made commits such that我已经做出了这样的承诺
commit hash - hash1 -> changes = a/1.txt, a/2.txt, b/1.txt
提交 hash - hash1 -> 更改 = a/1.txt, a/2.txt, b/1.txt
Now I'm reverting this commit by git revert -m 1 hash1
but I want to remove only changes done to folder a/
but want to retain the changes inside b/
现在我正在通过git revert -m 1 hash1
恢复此提交,但我只想删除对文件夹a/
所做的更改,但想保留b/
中的更改
Is it possible?可能吗?
git revert -m 1 hash1
# If needed, resolve conflicts and commit;
# those outside of a/ may be resolved arbitrarily.
git reset --hard HEAD^
git checkout hash1 a/
git commit -C HEAD@{1}
You could also use revert -n
and then reset all other directories before committing;您也可以使用revert -n
然后在提交之前重置所有其他目录; the recipe above is preferable only if there are many such other directories since it names only a
.只有当有许多这样的其他目录时,上面的配方才更可取,因为它只命名a
.
You can use --no-commit
.您可以使用--no-commit
。
git revert --no-commit <commit_id>
git restore --staged b/
git checkout .
git commit
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.