1

I have two branches lets assume that to be A and B

A is the master branch which will be used for production and B is another branch which I am using for testing in local.So I am working on branch B with local database and while sending emails i send it to myself since it should not be send to the guests while I am testing locally.

So I have a file named booking_confirmation.cs in which the email will be mine when I test locally and when I switch to master branch it will be the live guest emails.

So I have made few changes other than the email part I want the email to be the same so I won't have to change every time I switch the branch.Now my issue is I need only the other changes I make in the branch B of the file without any switch in emails.

What I tried is

I checked out the master branch to make sure it is in use

git checkout A

and then I checked out the specific file from branch B which I need in branch A so I tried

git checkout B booking_confirmation.cs

If there is no conflicts in the file which i am about to merge git auto merges it without any problems but if there are conflicts i get the below error

-not something we can merge

So is there a way to merge the file so that i can select/merge which part of the file i need in master branch.Any help would be really appreciated.

Thanks in advance !

Melvin
  • 877
  • 3
  • 11
  • 27
  • Have you get the answer which help you solve the problem? If yes, you can mark it as answer. And it will also benefit others who have similar questions. – Marina Liu Sep 12 '17 at 08:54

2 Answers2

0

So I have a file named booking_confirmation.cs in which the email will be mine when I test locally and when I switch to master branch it will be the live guest emails.

Well... that is a good opportunity for your code to be more robust to environment changes (like prod vs. test)

Said code could have one fixed value... unless an environment variable is set, in which case it would take as an email said environment variable.

Since it is configuration-related, see "The Twelve-Factor App: III. Config".

That would avoid the all "git checkout-preserve one line" issue.
You keep one identical code, but you override a value through an environment variable at execution, only during tests.


But if you must manage that one line through Git, you also have the possibility to put in place a content filter driver, which on checkout can assess the branch being checked out and put in the source file the right value.

https://git-scm.com/book/en/v2/images/smudge.png

(From the Git Pro Book): "Customizing Git - Git Attributes: Keyword Expansion")

The smudge script would be a simple sed, replacing the one line (in booking_confirmation.cs) declaring the email address with the proper value.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You can use interative window to merge the file booking_confirmation.cs by managing the merge confilcts/results manually:

git checkout A
git checkout --patch B  booking_confirmation.cs

Then you can handle the merge result for the file manually. Such as input y to apply the changes, input e to edit the changes manually etc.

Marina Liu
  • 36,876
  • 5
  • 61
  • 74