简体   繁体   中英

With git, how to force overwrite a file in one branch, from a file in another branch (bypass merge), and commit?

I have a single file in a branch called ' production ' that I want overwritten by a specific file in another branch called ' sqa '.

The nature of the file is that it is not code where there are multiple contributors.

What command would do this? (neither branch is master) - one branch is called ' production ' and the other ' sqa '.


The file in branch ' sqa ' I want to get into the branch ' production ' and have them be identical after running the command, avoiding any potential merge conflict (force overwrite, force accept the file in 'sqa') /sqa/file => /production/file .

If this is possible, and if anyone has actually done this and tested this, it would be so greatly appreciated (for a single file only, not multiple files or the whole branch merge).

If the file exists in branch ' sqa ' but not in ' production ', would the command work the same (to copy it there?)

You can bring over the file exactly as it is in another branch like this:

git checkout the-other-branch -- the-file

Then you can commit it if you want. It will hold no metadata about where it is coming from, just in case.

If what you want is copy a file so that it is saved with a different name , then it is like this:

git show the-other-branch:the-file > file-name-i-want
git add filename-i-want

Then you can commit. Then, just like in my previous example, there will be no metadata about where the file is coming from. It is just like you had written that file from scratch without help from git and then added/committed it.

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