[英]How can I see the list of all commits that affect a specific file with git (including orphaned or dangling commits)
I am using Git + Gerrit, and it is turning out to be a little more effort than I had anticipated. 我正在使用Git + Gerrit,结果比我预期的要多一些。
As a consequence of not yet having reached the top of the learning curve; 由于尚未达到学习曲线的顶部; I have lost some changes that I made to a file. 我丢失了对文件所做的一些更改。
I think that those changes might be in a previous commit that has somehow become orphaned in the merge-and-rebase song-and-dance routine that Gerrit seems to require. 我认为这些更改可能是在先前的提交中,该提交在某种程度上已经变成了Gerrit似乎要求的合并并变基础的歌曲和舞蹈程序的一部分。
How can I see the list of all commits (orphaned or not) that affect a particular file, so I can go through them one-by-one and try to find my changes? 如何查看影响特定文件的所有提交(孤立或未孤立)的列表,因此我可以一个接一个地浏览它们并尝试查找更改?
Don't know about Gerrit and "merge-and-rebase song-and-dance" parts, but in Git you can always revert back once you committed (unless you take special actions to prevent this). 不了解Gerrit和“合并和还原歌曲与舞蹈”部分,但是在Git中,一旦您提交就可以始终还原(除非您采取特殊措施来防止这种情况)。
First of all check what commit you're interested in: 首先检查您感兴趣的提交:
git reflog -- <file>
Once your (poor) orphaned commit's ID is known, you can do one of the following: 知道您的(较差的)孤立提交的ID后,您可以执行以下操作之一:
git merge <commit_id>
or 要么
git reset --hard <commit_id>
The choice between the two is up to you and is dependent upon the following factors (among others): 两者之间的选择取决于您,并且取决于以下因素(以及其他因素):
EDIT: 编辑:
Found an interesting trick: 找到了一个有趣的把戏:
git cherry-pick -n <commit_id>
this will aplly your orphaned commit over your current HEAD, but will not automatically commit the changes - you can checkout irrelevant stuff and keep only changes to the file in question. 这将在您当前的HEAD上增加您的孤立提交,但不会自动提交更改-您可以签出无关的内容,仅保留对相关文件的更改。
Note: I never used rebase, therefore it may be the case that this trick need some kind of adaptation to your case 注意:我从未使用过rebase,因此可能这种情况下需要对您的情况进行某种调整
You can use log
to get the list of commits. 您可以使用log
获取提交列表。 Doing this will show changes to file1 on all branches (see manpage for git-log
for more information): 这样做将在所有分支上显示对file1的更改(有关更多信息,请参见git-log
联机帮助页):
git log -g --pretty=oneline --all -- file1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.