2

我很难清楚地表达这一点,但我会试一试。

情况:

问题:


  • 我不在乎保持细微的差异。
  • 我希望我的代码将来可以轻松提取。
  • 我不想失去历史(我的或上游)。
  • 该解决方案会导致我未来的开发出现问题吗?

备择方案:

  • 有没有更简单的方法?
  • 我应该重命名这个分支(以某种方式)并重新开始吗?
    • (不知何故)在本地同步重命名并从新的主人那里工作?
    • 我现在应该忘记使用名为 master 的分支,因为这会给我带来问题吗?

Github 有问题:

4

2 回答 2

1

好吧,如果您不想丢失历史记录,最简单的事情就是始终创建一个功能分支,您可以在其中处理您的拉取请求。

在您的情况下(如果您想保留历史记录),请创建一个新分支

git checkout master
git checkout -b my-old-feature

然后,只需将您的主分支重置为上游主分支的任何点

git remote add upstream <upstream-repo-uri>
git fetch upstream
git checkout master
git reset --hard upstream/master

然后你有一个干净的状态,你的主分支将是上游分支。将来,只需始终保持 master 分支跟随上游/master 分支,并在您创建的功能分支上工作以防止与上游更新发生冲突。

编辑:
顺便说一句,我总是喜欢让我的分支与上游命名相同。但是您也可以在另一个分支名称上跟踪上游/主控。例如:

git pull upstream master:upstream-master

希望这有帮助!

于 2013-01-23T21:38:12.800 回答
0

你的意思是你的分支上有额外的提交,这些提交不在拉取请求中,你想将它们转移到新的主节点上?

使用git-rebase, 需要注意的是,如果你知道它在做什么,你真的应该只变基:

git rebase --onto upstream/master A B

在这里,A应该是您拉取请求中的最后一次提交,并且B应该是您本地分支的名称(可能是master)。

This will iterate over all the commits that come after your pull request and "replay" them, one at a time, on top of upstream's new master. By "replay" I mean git is literally generating a patch from each commit, applying it to the code, and making a new commit with the same date/author/message as the original. You'll have the same changes arranged the same way, but the commit hashes will be different. (So don't do this if anyone else has branched off of your branch!)

Another way to do the same thing is to create a new branch based on upstream, then git cherry-pick the commits you want to keep. This does exactly the same thing, replaying the commits, except you bring arbitrary other commits into the current branch rather than moving the current branch somewhere else.

于 2013-01-23T22:02:35.670 回答