简体   繁体   中英

replacing a file in a git branch with the same file from another branch?

Every time I update one of my git repo and fetch a new branch or commits I want to replace two of the new files with the ones in a specific branch.

I know that I can do that with checkout but...

What is the difference between

git checkout wanted_branch file_wanted

and

git checkout --merge wanted_branch file_wanted

?

In the form that you are mentioning, there is really no difference between the two and the --merge is superfluous.

--merge option is mainly used when you are switching branches and you have local modifications in your working directory, so that rather than just saying you cannot switch branches, you can make git to attempt to do a three-way merge on the modifications and present you with checked out branch with or without the conflicts.

Also, when you do git checkout --merge -- file during conflict, you get back the conflicted merge in file ( from the index)

The above two are the uses for --merge and in the form you mentioned, it is not different from git checkout some_branch -- file

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