[英]How to revert files to a previous commit but keep other files to latest commit
Assume I have these commits (the letters are the hash number): 假设我有这些提交(字母是哈希数):
-a(initial commit)
-b(implemented feature request affected foo.php and bar.php)
-c(someone else's commit)
-d(someone experimented on foo.php/bar.php and forgot to discard changes)
-e(another commit)
-f(latest commit)
How do I change foo.php and bar.php to what it was during commit "c". 如何将foo.php和bar.php更改为提交“ c”期间的状态。 So far I've tried
git reset c
and git reset --hard c
but it changes the whole repository instead. 到目前为止,我已经尝试了
git reset c
和git reset --hard c
但是它改变了整个存储库。
Another method I tried so far is to make another clone of the repo and reset --hard c
, then I manually copy pasted foo.php and bar.php to my working copy then I staged and pushed the changes to remote. 到目前为止,我尝试过的另一种方法是对存储库进行另一个克隆并
reset --hard c
,然后将粘贴的foo.php和bar.php手动复制到我的工作副本中,然后我上演并将更改推送到远程。
Just revert the file to that old commit, and commit the changes. 只需将文件还原到该旧提交,然后提交更改即可。
git checkout <old_commit_id> file_path
For instance - 例如 -
git checkout <hash_of_c> foo.php
git checkout <hash_of_c> bar.php
git add -u
git commit -m "revert foo and boo"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.