简体   繁体   English

git:无论分支如何,如何获取特定文件的最新提交?

[英]git: How to get the latest commit on a specific file, regardless of branch?

I have this big repository containing different modules, which should have been broken down in different repositories, one for each module. 我有一个包含不同模块的大型存储库,应该将其分解为不同的存储库,每个模块一个。 Sometimes I created a branch, say featbranch , in the repo to work on a specific module, but featbranch had no meaning at all for other modules. 有时,我在回购中创建了一个分支,例如featbranch来处理特定的模块,但是featbranch对于其他模块根本没有任何意义。 You can imagine the mess this could cause... 您可以想象这可能导致的混乱...

Anyway, my question is: how do I get the latest commit that changed a specific file, and possibly which branch such commit belongs to? 无论如何,我的问题是:如何获取更改特定文件的最新提交,以及该提交属于哪个分支? By "latest", I just mean the one with highest timestamp, as I understand that commits from different branches would likely not have any precedence relation. “最新的”是指时间戳最高的那个,因为我知道来自不同分支的提交可能没有任何优先级关系。

git log -n 1 --date-order --all -- <file>

(请注意,如果有人直接在较新的提交之上进行了“较早的”提交,则该提交可能不是带有最新时间戳的提交。但是,这仅可能是由于某人在撒谎的时间上是在撒谎。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM