Home > Mobile >  Git - commits and push of same repository from two different machines with differing folders
Git - commits and push of same repository from two different machines with differing folders

Time:09-16

I have the following folder structure:

AllMyWork/
  --.git/
  --Proj1/
     file1.cpp, ..., file10.cpp
  --WindowsOnly/ (this subfolder does not exist on Linux machine)
     filea.bat
  --LinuxOnly/ (this subfolder does not exist on Windows machine)
     fileb.sh

I alternate between working on Proj1 from a Windows machine and a Linux machine. Both machines share the exact same files/folder structure in terms of .git/ and Proj1/ and its contents file1.cpp through file10.cpp. What they don't share however are subfolders WindowsOnly/ and the associated file filea.bat (this is only available on the Windows machine) and subfolders LinuxOnly/ and the associated file fileb.sh (this is only available on the Linux machine).

Now, I did a commit / push from the Windows machine. When I open the Linux machine and issue command git status, I obtain:

deleted: WindowsOnly/filea.bat

This is understandable since Git thinks that this file was deleted since that folder does not exist on the Linux machine.

However, what happens now if I work on the common files in the Proj1 and commit / push from the Linux machine? The next time I open the Windows machine, would the subfolder WindowsOnly/ and filea.bat get deleted from the Windows machine since the most recent push from the Linux machine did not include those files?

ETA: How both the Windows machine and the Linux machine got to share the same .git/ and Proj1/ folder is that on each machine, I run GoogleDrive/Insync that automatically syncs these folders. On the Linux machine, I specifically instruct GoogleDrive/Insync not to download and sync WindowsOnly/ and on the Windows machine, I specifically instruct GoogleDrive/Insync not to download and sync LinuxOnly/.

CodePudding user response:

I wouldn't say needlessly. You need those files to support the project on both platforms. It's not like linux (the kernel project) has different branches/repos to support the number of architectures they support. It's a single project with all the architectures in a single plate.

Just in case, in order to pull this off, what I would do is have a common branch (say, main) with Proj1, then a windows branch and a linux branch both created from main. The windows branch is where you hack WindowsOnly stuff (that's the only branch where that directory is held) and then in linux branch you hold LinuxOnly.

You could even go as far as create linux branch from windows branch (or viceversa) (making sure to delete the files from the other architecture) just so that git can see the relation between the files (if there's any). That might ease a little bit stuff when you want to cherry-pick changes from one architecture to the other, but you are kind of going into deeper waters if you want to try this trick (it's doable.... but you need to have a higher git-zen level to understand why git will complain one way or the other when trying to move around stuff between the two architecture branches).

  •  Tags:  
  • git
  • Related