Git: Track two branches, when files are located differently on each one
Given I'm on first branch, tracking 'foo' and 'bar' files, like this:
my_repository/
./foo
./bar
How could I also track another branch (remote), where this 'foo' and 'bar' files are located under another location? I.e., when I checkout this second branch, my_repository
folder turns into something like this:
my_repository/
./some_file
./another_file
./tests/
../foo
../bar
Explaining a bit more: I have first branch tracking a re开发者_C百科mote repository, and second branch tracking another remote repository.
In some point, I cloned second repository somewhere-else, added foo
and bar
files to tests
folder, and commited it.
Then, I started commiting and making changes to my foo
and bar
files from my first branch, my oficial clone (origin/master). Now, I'd like to also send this changes to second repository, but not just overriding files's content. I'd like to have the commit history on the second branch too.
The problem is that this second repository place my files onto a different location.
Any tips?
It looks like you are looking for the subtree merge strategy (see also here).
There should not be any problem. There are two trees with some content. You merge them and put the files in one or another place in the merge and push that merge.
Git does not track file identities, but when it does a merge and notices a file that was modified on one side and does not exist on the other, it looks for files with sufficiently similar that the changes may have chance to apply. So if the files are similar, git will merge them (and you can move them to the other location if you wish), if they are different, it will just give you both and you'll have to choose (but than trying to merge them would be conflict anyway, so not tracking file identities did not loose anything).
精彩评论