5

Our project has a develop branch. I created a bug-fix branch based on the develop branch, and changed one file a.java. And I know another people changed the a.java and merged to develop branch when I was fixing the bug.

Now I have fixed the bug, I want to merge my code to develop branch, but before I do that, I want to pull the changes(since other guy changed the a.java as well) to my local branch to test if it works, am I right? How can I do it?

Firstly I pulled all the code by 'git pull', and I am in my bug-fix branch. then run 'git merge develop', it output empty. Then I 'git merge origin/develop'.It output below errors.

Updating 46f689b..3011608
error: Your local changes to the following files would be overwritten by merge:
        projectA/a.java
Please commit your changes or stash them before you merge.
Aborting

How can I merge the develop branch to my working directory?Thanks.

liam xu
  • 2,892
  • 10
  • 42
  • 65

4 Answers4

5

Normally in this situation here is what I like to do,

git stash # Stash your local changes
git pull  # Update code
git stash apply # Merge your local changes

Now, for clarification, you can switch branch before your git pull if you need to synch another branch. From there you can come back on your bug-fixes branch and run git stash apply to then merge with your develop branch.

scharette
  • 9,437
  • 8
  • 33
  • 67
2

Because you have some changes on that file

Please commit your changes or stash them before you merge.

Just follow this:

# save current work state
git stash
# merge from develop
git merge origin/develop
# recover current work state (get the last item of stash)
git stash pop
Vuong
  • 617
  • 11
  • 26
1

Since you haven't push your local commits on the bug branch, you need to rebase them on top of the updated (by the other developer) origin/bug branch.

For that, make sure you have set first the configuration:

git --global config pull.rebase true
git --global config rebase.autoStash true

(to be done only once, from any folder)

Then, while you are in your current branch, you can include contribution of other with a simple:

git pull.

Now, make sure everything is committed, and:

git checkout develop
git pull

Finally, merge develop

git checkout bug
git merge develop
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You need to commit or stash your changes to projectA/a.java before merging in other changes.

Commit Example:

$ git add projectA/a.java
$ git commit -m "my change message"
$ git pull origin/develop

Stash Example:

$ git stash
$ git pull origin/develop
$ git stash apply
Steve Mulvihill
  • 688
  • 6
  • 13