如何在Git的所有分支中签出文件的最新更新版本?

时间:2019-01-23 17:48:35

标签: git

我在Sub MailMerge() Set wordapp = CreateObject("word.Application") wordapp.documents.Open "C:\Users\me\Desktop\hello.docx", ReadOnly:=True wordapp.Visible = True With ActiveDocument.MailMerge .Destination = wdSendToEmail .SuppressBlankLines = True With .DataSource .FirstRecord = wdDefaultFirstRecord .LastRecord = wdDefaultLastRecord End With .Execute Pause:=False End With End Sub 分支的Git存储库中的整个工作中都更新了一个文件。我目前在另一个分支上,基于对master的较旧提交,因此我看到的文件版本已过时。我没有触及当前分支上的文件。

我想签出该文件的完整更新版本。我知道该文件的最新更新版本(甚至跨所有分支)是我想要的版本,但是我不知道那是哪个提交。

是否可以在所有分支和提交中检出给定文件的最新版本?(我希望使用一种方法)

1 个答案:

答案 0 :(得分:1)

如果文件为dir/foo,则在所有分支上获取最新提交的方式如下(更多信息heregit-rev-list(1) Manual Page):

git rev-list -1 --branches=* dir/foo

基于提交检出文件的方法是(更多信息here):

git checkout <commit> dir/foo

因此,单线解决方案(例如BASH)是:

git checkout `git rev-list -1 --branches=* dir/foo` dir/foo