There's a special place in hell for people who hardcode absolute paths and database credentials into multiple random places in web applications. Sadly, before they go to hell they're wreaking havoc on Earth. And we have to deal with their code.
I have to perform a few small changes to one of such web applications. I create a new branch features
, and perform a global find & replace to update the paths and credentials to my local environment. I commit that. I also tag this as local
.
I merrily leap into perilous hacking penitence, and after a perplexing hundred patches, I want to merge my features
changes into the master
branch, but I do not want the one local
commit to be merged.
Onwards, I'll be merging back and forth between master
and features
, and I'd like local
to stay put in features
, and never ever show up in master
.
Ideally, I'd like all this to happen magically, with as little funny parameters and whatnot as possible.
Is there a simple obvious way to do it that I'm missing?
I can think of a couple, but they all require me to remember that I don't want that commit. And that's definitely not my forte. Especially with such poorly hacked programs.
Failing that, I'm interested in more convoluted, manual-ish ways to handle the situation.
It allows you to merge(unshelve) a shelveset into a specific branch. Using Source Control Explorer in Visual Studio, get the history for any folder or file. Select one or more changesets in the list and right-click your selection. The context menu will now have a 'Merge...' option.
In fact, all you need to do to merge unrelated branches is to use the flag --allow-unrelated-histories . This tells Git to combine all the files and commits of both unrelated branches into one branch, as long as there are no file conflicts.
To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.
My solution to this problem uses rebase rather than merge
Starting with a commit tree like this:
a-b-c <-- master
\
d <-- local
\
e-f-g <-- dev
$ git rebase --onto master local dev
master
V
a-b-c-e'-f'-g' <-- dev
\
d <-- local
$ git checkout master
$ git merge dev
master
V
a-b-c-e'-f'-g' <-- dev
\
d <-- local
$ git rebase --onto master master local
master
V
a-b-c-e'-f'-g' <-- dev
\
d' <-- local
$ git branch -f dev local
master
V
a-b-c-e'-f'-g'
\
d' <-- local
^
dev
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With