1

Don't know, how to describe it in a short title... Here is my problem.

We have two branches feature-100, feature-150 and the develop-branch.

I'am working on 150, and need a feature from branch-100. Branch-100, is some weaks old, and were never been merged to develop. One fellow, bring the changes from 100 via cherry-pick to develop. So the idea way, just "update" my 150 with the current develop, to get this treasured feature.

I've try my branch

  1. merge from develop
  2. rebase my branch from develop

But all this actions overwrites my changes on the branch. One info more, my changes on 150 are already pulled on remote/150.

Any idea, how to handle this ?

2 Answers 2

3

One info more, my changes on 150 are already pulled on remote/150.

That means rebasing feature-150 on top of develop isn't a good idea, as it would rewrite the history of that branch.

Merging should be the right option:

git checkout feature-150 git merge develop 

That shouldn't overwrite your changes. If it does, try a merge strategy specific option ours from git merge: that would select your changes in case of conflict.

git merge -X ours develop 

If that still fails, the OP codesnippet points (in the comments) to a workaround:

I've merged now, whereby my changes were overwritten, after that I'd use cherry-pick for my tree commits to "force overwrite" with my changes.
Maybe there are some other/better ways to realize this, but this is my solution.

Sign up to request clarification or add additional context in comments.

4 Comments

This "ours" otpion seems to be a good idea. But it doesn't work for me. I don't know why... I asume that there "some doings" on the branches that I do not consider. I've merged now, whereby my changes were overwritten, after that I'd use cherry-pick for my tree commits to "force overwrite" with my changes. Maybe there are some other/better ways to realize this, but this is my solution.
@codeSnippet Were you changes (that are overwirtten by the merge) committed on feature-150 before the merge?
@codeSnippet ok. I have added your workaround in the answer for more visibility.
@codeSnippet, did you manage to understand and sort this out? I'm doing the same and git merge just keeps on overwriting my changes (I have 10 files locally, and 2 new on an origin/remote_branch, when I do `git merge origin/remote_branch master' (when I am in local/master). It deletes my 10 local files and bring the 2 new? I want to keep my 10 local files and bring the 2 new? any clue what command I could use?
-1

What do you mean by "overrides my changes"?

Before doing anything else commit your changes! This way they are stored as a commit and git knows about them.

Afterwards both merge and rebase should do fine.

3 Comments

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
Git does not override committed changes. Therefore the only meaningful way to interpret the question is the existence of uncommitted changes. Therefore the solution is to commit those changes.
I think the OP means that they are merging master in and the result of the merge is that the changes on the branch are removed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.