我可以告诉git拉覆盖而不是合并? [英] Can I tell git pull to overwrite instead of merge?

查看:131
本文介绍了我可以告诉git拉覆盖而不是合并?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所见, git pull someRemote master 尝试将远程分支合并到我的。



有没有办法说完全丢弃我的东西,只是让我使用git pull的另一个远程克隆?我仍然想保留我自己的存储库并保留它的历史记录,但是我希望在该命令后有1:1的someRemote主分支副本。

为了说明,想象一下有2个知识库,RM和MY。数字是提交,并且这只假设一个分支(主)。

 
RM1 --- RM2 --- RM3 --- RM4 - - RM5 --- RM6 ...
| |
+ - > MY1 --- MY2 --- MY3 - + - > MY4 --- MY5 --- MY6 ...

因此,我开始将自己的存储库作为RM1的克隆。然后我开心地开发,RM开心开心,但我们从不分享我们的工作。在MY3之后,我意识到我的分支不是那么棒,但是RM4相当不错。所以我想将 git pull RM4放入MY。不过,我不希望我的MY1-3的变化持续存在,我想让MY4成为RM4的1:1副本。

然而,我想保留我的我希望在MY3和RM4之间或者MY3和RM2-4之间有一个变化。

b
$ b

这是可能的吗?



(这适用于GitHub项目,我可以分解一个项目,做一点实验,几个星期,但然后想要更新它,但没有保留我的更改。目前我删除我的叉和重新叉,这不是最好的办法。)

解决方案

首先,将您的主分支重命名为其他名称:

  git branch -m master my_old_master 

然后,创建一个新的主人:

  git checkout -b master someRemote 

Git的优点是分支名称是他们不是真正的地方,他们是只是指向地方的指针(其中place是SHA1提交ID)。


As far as I see, git pull someRemote master tries to merge the remote branch into mine.

Is there a way to say "Completely discard my stuff, just make me another clone of the remote" using git pull? I still want to keep my own repository and keep it's history, but I want to have a 1:1 copy of someRemote's master branch after that command.

To clarify, imagine there are 2 repositories, RM and MY. Numbers are commits, and this assumes only one branch (master).

RM1 --- RM2 --- RM3 --- RM4 --- RM5 --- RM6 ...
|                        |
+-> MY1 --- MY2 --- MY3 -+-> MY4 --- MY5 --- MY6 ...

So I start my own repository as a clone of RM1. Then I develop happily and RM develops happily, but we never share our work. After MY3 I realize that my branch isn't that great but that RM4 is pretty good. So I want to git pull RM4 into MY. However, I don't want my changes in MY1-3 to persist, I want MY4 be a 1:1 copy of RM4.

However, I want to keep my history, ideally I would like to have a change set between MY3 and RM4 or between MY3 and RM2-4.

It should still stay my repository.

Is that possible?

(This is for GitHub projects where I may fork a project, experiment a bit, leave it alone for a few weeks but then want to update it without keeping my changes. At the moment I delete my fork and re-fork, which isn't the best approach.)

解决方案

First, rename your master branch to something else:

git branch -m master my_old_master

Then, create a new master:

git checkout -b master someRemote

The great thing about Git's branch names is that they aren't actual places themselves, they're just pointers to places (where a "place" is a SHA1 commit id).

这篇关于我可以告诉git拉覆盖而不是合并?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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