1

I am working in branch let say b1. The main branch that is to be deployed is let say stage. I forked my b1 branch from master - this is our convention.

So here is the situation. I am currently in b1. In one file, I will call it users.txt there is a snippet that looks like this:

print("Hello user")
print("Bye user")

In stage branch the same snippet looks like this:

print("Hello user")
print("You are welcome")
print("Bye user")

Now in my working (b1) branch I am suppose to make such change that when merged to stage will remove this line: print("You are welcome") and make the stage branch look like it. In other words after executing git checkout stage git merge b1 - the stage file user.txt to look like this:

print("Hello user")
print("Bye user")

In yet other words: Remove line in branch stage, by making the change in branch b1 where the line that is to be removed does not exist in b1 in the first place.

One caveat: I am not allowed to merge stage into b1 by convention(to be honest - I don't understand)

Hairi
  • 3,318
  • 2
  • 29
  • 68
  • How was `stage` created? Was it also forked from `master` and got progressed independently? – Manish Bansal Jun 03 '19 at 08:44
  • Yes, Stage is changed vial merge from multiple development branches like `b1` and somewhere, by some merge this line appeared `print("You are welcome")`. So I am suppose to remove that line, but THAT line simply does not exist in my development branch `b1` – Hairi Jun 03 '19 at 08:46
  • Ideally your development branches should be forked from `stage`. You should keep `master` for mirroring production code. Merging independent `dev` branches forcefully into `stage` will simply override previous `dev` branch chages which does not make much sense. – Manish Bansal Jun 03 '19 at 08:50
  • Probably you are right. The circumstances are strange here I admit. I asked the same question: Me: so can I merge STAGE to the my b1 branch? Boss: No. It will make it not possible for me to make an isolated deploy then. But you can merge the branch where this feature presents. – Hairi Jun 03 '19 at 08:53
  • 1
    Does [cherry-pick](https://stackoverflow.com/questions/9339429/what-does-cherry-picking-a-commit-with-git-mean) work for you? – Theraot Jun 03 '19 at 08:55
  • For such cases, deployments should be done from your feature branches directly. Not by merging it to stage. This needs a fix in your deployment pipeline. I hope you have a single member team. Otherwise i can imagine the chaos happening in your team. – Manish Bansal Jun 03 '19 at 08:58
  • @Theraot I think it will. I will go for your approach. Thanks. – Hairi Jun 03 '19 at 09:01

1 Answers1

0

(Disclaimer for obsolete answer : question was edited after my answer, now stage shouldn't be merged into the feature branch)


Since b1 and stage have different initial states for the users.txt file, you'll first have to update b1 to catch up with recent changes, namely the new line it lacks.

git checkout stage
git pull
git checkout b1
git merge stage

At this point you might (or not) have to resolve conflicts. Then your users.txt will be similar to the one on stage. Just delete the line, add and commit :

# go delete the line in "users.txt" then...
git add path/to/users.txt
git commit -m "Deleted said line"

Edit after your comment about no merging stage into features

If you can't merge stage in, but are allowed to merge the feature the line originated from, go for it. You'll have to locate which commit it comes from :

git log -1 --oneline -S "Copy the text of the line here"

This will output the last commit which touched the line. Note its hash. You can then import that commit in your branch with a cherry-pick, as hinted at by Theraot in comments.

git cherry-pick <commitHash>
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
  • Yes it would do the job for me, but my Boss does not allow to merge `stage` to our development branches. I assume, what I am asking for here might not be possible at all, but I have to be sure there is no decent way to do that before I get into an argument with my boss – Hairi Jun 03 '19 at 08:47