简体   繁体   中英

How to merge with master in a git branch that has uncommitted changes

I am currently working on a branch foo and a colleague has made changes that are part of master . I have uncommitted changes on my branch, which I want to keep, but would also like to bring down the recent changes that are now part of master .

I assumed that git merge origin/master would do this (ie merge that location with my current branch). To perform the merge, it would keep my local work, and apply any changes from the repo that weren't part of my local changes.

However, this doesn't seem to work. It seems not to do anything.

ems@host:~/test$ git merge origin/master
Already up-to-date.

On the other hand, this answer suggests that you can't even do this action, and must merge uncommitted changes first before pulling.

What is the correct way to bring down changes from master to a current branch without being forced to commit work in progress?

git pull origin master should work, but I think you can stash your changes, pull from master than apply the stash so:

git stash 
git pull origin master [or origin/master if you want to use the local stored branch]
git stash apply

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM