简体   繁体   中英

How to merged only changed files from a past branch into the master in GIT?

Say I create a local branch named fix_5109 and work on it. In the meantime the master branch changes and some files which I'm NOT editing are normally changed(eg. /controllers/AuthController.php). If I push my changes to origin fix_5109 the lead developer wants to merge my branch into the master if all went alright. My branch contains the old AuthController.php from an older commit behind master's newer. Will the file in the master branch be overwritten by my version of the file or would it reject my version of that file and update only the files I've edited in the branch I've pushed?

git functions in a way where if a commit is already applied, it won't be applied again (Uniqueness by commit hash). So for your case, assuming you had diverged from master at some point in time when the changes to AuthController.php had already been made, then you don't have to worry. Since, git would not replay a existing commit.

So even if your lead merges changes from your branch. He will basically have the latest code. ie) what ever change was last made (without diverging). If the changes were made separately, then git would try to resolve the commits and apply them one after the other. In this case, if there is a conflict then you would need to handle it explicitly.

git checkout master
git pull origin master
git checkout fix_5109
git rebase master

Basically rebasing your branch with the current state of master will take care of the issue you are concerned about.

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