Question

I am a C# developer and trying to figure out Git. It's a much different environment than what I am used to in a centralized VCS (I am very comfortable with TFS). I've watch some excellent Pluralsight videos on Git and went through tutorials and feel confident in basic Git functionality, however I think I am missing something fundamental regarding merging/rebasing.

I have forked and modified mediawiki quite a bit as well as some of its extensions (forked those as well and repointed my .gitmodules to point at my forked version). I currently have 1.22.5 (corresponds to branch REL1_22) deployed to production and is where I have made all my changes. I have also commited my submodule changes. These changes prompt another change in the main repo to repoint the submodule references to point to the new commits.

Here's the part that escapes me. Suppose I want to reproduce my changes in master. In TFS, each branch in separate directories. When you merge, all of your code is duplicated in the other directory, deal with conflicts and check in. With Git, I switch branches with git checkout master leaving me in the same directory (though I understand that Git restores the snapshot that the destination branch is pointing to, adding/removing files and folders as necessary). At this point, how do I merge just my changes for submodules+main? Do I use git merge <SHA-1> to merge specific commits in my submodules, then git merge again in the main project (with updated submodule reference SHA-1s)? Is there a cleaner way to wrap everything up in one branch and merge just that branch to master (and other release branches)? Maybe git rebase is what I am looking for, to replay all my changes on another branch?

Was it helpful?

Solution

At this point, how do I merge just my changes for submodules+main?

Merge your branch normally in the main repo (the one including your submodules).
That will update the gitlink (special entry mode 160000) representing the updated SHA1 of your submodules: when you merge in a main repo, you don't merge file in submodules, you just update those gitlink SHA1.

Then, after the merge, run a git submodule update, to update the content of those submodules.

Merging a branch in the parent repo doesn't mean you have to merge anything in a submodule: the submodule is there to dissociate the development of a nested git repo from its parent repo, while keeping a precise reference of the former in the latter (the gitlink).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top