git 将分支内容复制到 master
git copy branch content to master
我有一个 git 项目,稳定版本总是存储在 master 分支中。
有一段时间我在一个单独的分支 v20 中开发 2.0 版。
现在我决定发布它并再次将所有内容复制到 master 分支。
我不想合并它,因为有数百个相互冲突的更改,而且很多文件需要手动干预。
我只想制作 v20 分支的快照并将其放入 master 中,而不影响旧历史,无需 rebase(因此其他用户也不会受到影响)。只是为了让它看起来像是一个带来了所有更改的新提交。
开始状态:
master branch --------- v20 branch
| |
master files --------- v20 files
| |
master_history v20_history
目标状态:
master branch --------- v20 branch
| |
v20 files -------- v20 files
| |
master_history v20_history
+ commit from v20
是否有现成的 git 方法来做到这一点?
您正在描述 git merge -s theirs
、which does not exist, and one of the main Git authors insists that it should not exist 的结果:。引用link(这些不是我的话):
Heh, now you have some readings to do ;-)
I tried not to sound too negative when describing -Xours
and -Xtheirs
there, but actually I think "-s theirs" is even worse. It is how you
would discard what you did (perhaps because the other side has much better
solution than your hack), but that can be much more easily and cleanly
done with:
$ git reset --hard origin
Some people might say "But with 'merge -s theirs', I can keep what I did,
too". That reset is simply discarding what I did.
That logic also is flawed. You can instead:
$ git branch i-was-stupid
$ git reset --hard origin
if you really want to keep record of your failure.
One big problem "-s theirs" has, compared to the above "reset to origin,
discarding or setting aside the failed history" is that your 'master'
history that your further development is based on will keep your failed
crap in it forever if you did "-s theirs". Hopefully you will become a
better programmer over time, and you may eventually have something worth
sharing with the world near the tip of your master branch. When that
happens, however, you cannot offer your master branch to be pulled by
the upstream, as the wider world will not be interested in your earlier
mistakes at all.
您可以随意不同意 Git 的人,并继续使用 Is there a "theirs" version of "git merge -s ours"? Note that the accepted answer is not truly a -s theirs
at all. Michael R's answer 的一些答案,在 [=] 期间使用 git read-tree
切换索引17=]合并,正确。
另一个SO问题 is also good, and jthill's answer中的方法也是正确的。
你的情况与上面描述的有点不同,但实际上,你可以重命名 "bad" 分支并将 "good" 分支重命名为 master
并继续从那里。您 "downstream" 中的任何人都需要同样的重命名,因此有多个要点需要考虑。
我有一个 git 项目,稳定版本总是存储在 master 分支中。 有一段时间我在一个单独的分支 v20 中开发 2.0 版。
现在我决定发布它并再次将所有内容复制到 master 分支。 我不想合并它,因为有数百个相互冲突的更改,而且很多文件需要手动干预。
我只想制作 v20 分支的快照并将其放入 master 中,而不影响旧历史,无需 rebase(因此其他用户也不会受到影响)。只是为了让它看起来像是一个带来了所有更改的新提交。
开始状态:
master branch --------- v20 branch
| |
master files --------- v20 files
| |
master_history v20_history
目标状态:
master branch --------- v20 branch
| |
v20 files -------- v20 files
| |
master_history v20_history
+ commit from v20
是否有现成的 git 方法来做到这一点?
您正在描述 git merge -s theirs
、which does not exist, and one of the main Git authors insists that it should not exist 的结果:。引用link(这些不是我的话):
Heh, now you have some readings to do ;-)
I tried not to sound too negative when describing
-Xours
and-Xtheirs
there, but actually I think "-s theirs" is even worse. It is how you would discard what you did (perhaps because the other side has much better solution than your hack), but that can be much more easily and cleanly done with:$ git reset --hard origin
Some people might say "But with 'merge -s theirs', I can keep what I did, too". That reset is simply discarding what I did.
That logic also is flawed. You can instead:
$ git branch i-was-stupid $ git reset --hard origin
if you really want to keep record of your failure.
One big problem "-s theirs" has, compared to the above "reset to origin, discarding or setting aside the failed history" is that your 'master' history that your further development is based on will keep your failed crap in it forever if you did "-s theirs". Hopefully you will become a better programmer over time, and you may eventually have something worth sharing with the world near the tip of your master branch. When that happens, however, you cannot offer your master branch to be pulled by the upstream, as the wider world will not be interested in your earlier mistakes at all.
您可以随意不同意 Git 的人,并继续使用 Is there a "theirs" version of "git merge -s ours"? Note that the accepted answer is not truly a -s theirs
at all. Michael R's answer 的一些答案,在 [=] 期间使用 git read-tree
切换索引17=]合并,正确。
另一个SO问题
你的情况与上面描述的有点不同,但实际上,你可以重命名 "bad" 分支并将 "good" 分支重命名为 master
并继续从那里。您 "downstream" 中的任何人都需要同样的重命名,因此有多个要点需要考虑。