Always ignore specific commit when merging in git

I am working on my first project using git and ran into a problem.

The repo contains a client / server application. I have a โ€œmasterโ€ and โ€œtestโ€ branches with the intention that the master always matches what was deployed.

My problem is 3-4 places in the code base where the server URL is stored. I want to change this in the "test" branch, but not in the "master" branch. The problem, of course, is that whenever I want to merge with the "master", git wants to make this change to the "master".

I can do a selective merge and merge all the commits, but the one in question, but that seems tedious for every single merge. What is the best way to do this?

I have never had this problem in any SCM, so maybe I'm just wrong.

+5
source share
2 answers

You want to merge this change as not merged, but mark it that way in history. This way you will find out where to get subsequent changes.

There are several ways to do this. One of them -

git checkout master git merge -s ours --no-ff testing git checkout testing git merge -s ours --no-ff master 

or

 git checkout master git merge testing --no-commit --no-ff git checkout HEAD -- . git submodule update # this is optional and only needed if you have submodules git add -A git commit git checkout testing git merge master --no-commit --no-ff git checkout HEAD -- . git submodule update # this is optional and only needed if you have submodules git add -A git commmit 

Now you have 2 branches with different configurations, but those that are committed are in front of the important merge-base .

Now you need the script to do something similar to perform a special merge, which is actually a submenu at the bottom - this is the only way to ignore what it was before:

 git checkout master git merge --no-ff -s ours testing git checkout -b temp testing git rebase -s recursive -Xtheirs master # these are the conflicts we care about git reset --soft HEAD@ {2} git add -A git submodule update git commit --amend -C HEAD@ {2} git push . +HEAD:master git checkout master git branch -d temp 

It just minimizes what you don't have branches testing on the server and makes it look like a merge. Since it stores it as a merge, you can subsequently run it against other branches that you want to publish in order to execute the wizard. Thus, you can separate all of these commands with && s, replace testing with an argument, a wizard with second argument variables, and an alias:

 git config alias.smart-merge '...' 

so you can post these changes:

 git smart-merge testing master git smart-merge feature2 master 

which should give you both testing and function2, no matter at what point these 2 can already be combined in history.

Also consider enabling reerere as the script does not expect conflicts. Therefore, if you want to publish, you can perform a normal reboot first, recording conflict resolution. You can now modify the script to take advantage of these and not break conflicts.

Restoring conflict resolution can be a pain. But not in this case, since we use only the wizard for publication. Other branch manipulations are still performed using regular merge or redirection.

- OR -

Nontrivial - these are pure smudge scripts. Take a look at the git attribute section in progit.org/book.

Hope this helped.

+1
source

git cherry-pick will let you do this (although you will need to select the commits to merge (and make sure you don't forget)

Another way is that you can git revert commits that changed the url, combined to execute the wizard, and then return it to your main branch.

Another way to do git commit --no-commit , and then modify the file, git add it before committing.

Another method that may not allow you to โ€œforgetโ€ should have this configuration (URLs, etc.) in a separate file and add this file to .gitignore ...

I donโ€™t think any of them are really elegant, but it will work ...

0
source

All Articles