我可以告诉 git pull 覆盖而不是合并吗?
据我所知, git pull someRemote master 尝试将远程分支合并到我的分支中。
有没有办法使用 git pull 说“完全丢弃我的东西,只需为我制作另一个远程克隆”?我仍然想保留我自己的存储库并保留它的历史记录,但我想在该命令之后拥有 someRemote 的 master 分支的 1:1 副本。
为了澄清这一点,假设有 2 个存储库:RM 和 MY。数字是提交,这假设只有一个分支(主分支)。
RM1 --- RM2 --- RM3 --- RM4 --- RM5 --- RM6 ... | | +-> MY1 --- MY2 --- MY3 -+-> MY4 --- MY5 --- MY6 ...
所以我创建了自己的存储库作为 RM1 的克隆。然后我快乐地发展,RM也快乐地发展,但是我们从不分享我们的工作。 MY3之后我发现我的分行不是那么好,但是RM4已经很不错了。所以我想git pull
RM4 到我的。但是,我不希望 MY1-3 中的更改持续存在,我希望 MY4 是 RM4 的 1:1 副本。
然而,我想保留我的历史记录,理想情况下我想在 MY3 和 RM4 之间或在 MY3 和 RM2-4 之间设置零钱。
它仍然应该保留在我的存储库中。
这可能吗?
(这是针对 GitHub 项目的,我可能会分叉一个项目,进行一些实验,将其单独放置几周,然后想更新它而不保留我的更改。目前,我删除了我的分叉并重新分叉,这不是'是最好的方法。)
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.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,将您的 master 分支重命名为其他名称:
然后,创建一个新的 master:
Git 分支名称的伟大之处在于它们本身并不是实际的位置,它们只是指向位置的指针(其中“位置”是 SHA1)提交 ID)。
First, rename your master branch to something else:
Then, create a new master:
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 checkout,这将丢弃您对路径的本地更改。
您可以使用 checkout 恢复更改:
将从索引恢复 myfile.h
http://git- scm.com/docs/git-checkout
Sounds like you're after git checkout, which will discard your local changes to a path.
You can revert your changes using checkout:
will restore myfile.h from the index
http://git-scm.com/docs/git-checkout
如果您想保留当前的主分支但注册新版本(镜像远程分支),您可以;
keepTheir
one)git pull --no-commit
If you want to keep your current master branch but register a new version (mirroring the remote branch), you can;
keepTheir
one)git pull --no-commit