简体   繁体   中英

GIT: Checkout file of other branch and automatically prefix it with branch name

To gather some stuff from different branches, I'd like to have the file from differnt branches simultaneously present in my editor.

Is it possible to checkout the same file from different branches and automatically prefix/suffix each of them with the branch they are from?

Such that I end up with the following file structure:

myProject/myfile.cpp // version of currently checked-out branch
myProject/branch1-myfile.cpp // versions from other branches
myProject/branch2-myfile.cpp
myProject/branch3-myfile.cpp

There's no magic git command that will do this, but as with many automation tasks a short shell script would take care of it...

for branch in branch1 branch2 branch3; do
    git show $branch:myfile.cpp > $branch-myfile.cpp
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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