Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIT - Use the latest version of the file from all branches

Do you know how to use the latest version of the file from all branches? The problem is that to use the latest version, I have to checkout the branch, but I do not know which branch is the latest version.

So I may use a file that is obsolete from another branch, but I do not know that another branch has the last version.

Partial Solution: Create a new branch where the last version of the file will be.

Can it be solved otherwise? Thanks

like image 324
HoumerX Avatar asked Jan 30 '23 14:01

HoumerX


1 Answers

I would guess that you using git the wrong way if you're asking this kind of question.
The notion of "latest version" of a file has no real sense in git.
The notion of "next version to be released" of a file depends on your branch and release workflow, but should be deterministic.

Maybe you should explain your root need for better understanding of want you're trying to achieve.


But, to strictly answer your question:

To find the latest commit that modified a file:

git log -1 --date-order --all --format=format:%H -- path/to/file/in/repository

This will give you the commit hash.

If you want to retrieve the content of the file in this commit:

git show ${COMMIT_HASH}:path/to/file/in/repository

If you want to find the branches containing this commit:

git branch --contains ${COMMIT_HASH}
like image 108
zigarn Avatar answered Feb 05 '23 16:02

zigarn