如何使用Git和命令行在合并期间保留本地文件或远程文件? [英] How to keep the local file or the remote file during merge using Git and the command line?

查看:15
本文介绍了如何使用Git和命令行在合并期间保留本地文件或远程文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道如何使用 vimdiff 合并修改,但是,假设我只知道整个文件可以保留或丢弃,我该怎么做?

I know how to merge modification using vimdiff, but, assuming I just know that the entire file is good to keep or to throw away, how do I do that?

我不想为每个人打开 vimdiff,我想要一个显示保持本地"或保持远程"的命令.

I don't want to open vimdiff for each of them, I change want a command that says 'keep local' or 'keep remote'.

EG:我合并了标记为已更改的文件,因为有人在 Windows 下打开它,更改 EOL,然后提交.合并时,我只想保留自己的版本并丢弃他的.

E.G: I got a merge with files marked as changed because somebody opened it under windows, changing the EOL, and then commited. When merging, I want to just keep my own version and discard his.

我也对相反的情况感兴趣:我把时间搞砸了,想接受远程文件,放弃我的更改.

I'm also interested in the contrary: I screwed up big time and want to accept the remote file, discarding my changes.

推荐答案

你也可以这样做:

git checkout --theirs /path/to/file

保留远程文件,以及:

git checkout --ours /path/to/file

保存本地文件.

然后 git add 它们就完成了.

Then git add them and everything is done.

版本:请记住,这是针对 merge 场景的.在 rebase 期间,--theirs 指的是你一直工作的分支.

Edition: Keep in mind that this is for a merge scenario. During a rebase --theirs refers to the branch where you've been working.

这篇关于如何使用Git和命令行在合并期间保留本地文件或远程文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆