Pablo Marin-Garcia
Pablo Marin-Garcia

Reputation: 4251

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

?

Upvotes: 8

Views: 1772

Answers (1)

manojlds
manojlds

Reputation: 301117

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

Upvotes: 3

Related Questions