Bra*_*son 190 git version-control
我已经使用Git大约一年了,并认为这太棒了,但我刚刚开始了该项目的第二个版本,并开始了一个新的分支.我正在努力处理未来的最佳方法.
我有两个分支叫做master10(对于v1)和master20(对于v2).我一直在分支master10上的v1中修复bug,并开发master20的新东西.每当我修复bug时,我都会通过检查master20并将其合并到v2中git merge master10.到现在为止还挺好.
然而,现在我在v1中做了一个我不想要的改变,但是我想继续合并其他错误修复.我如何告诉Git跳过该特定提交(或一系列提交),但是未来我仍然希望合并其他错误修复.
我认为git rebase可能是我需要的,但阅读文档和我的头几乎爆炸.
我想我想要的就像是一个"git sync"命令,它告诉git两个分支现在是同步的,并且将来只会合并来自这个同步点的提交.
任何帮助赞赏.
ara*_*nid 280
例如,如果要将分支"maint"上的大多数提交但不是所有提交合并到"master",则可以执行此操作.它需要一些工作----如上所述,通常的用例是合并一个分支中的所有内容---但有时会发生一个不应该集成的发布版本的更改(可能是代码的已经被大师取代了),你怎么代表呢?开始...
因此,假设maint已经应用了5个更改,其中一个(maint~3)不会合并回master,尽管其他所有应该都是.你在三个阶段完成这个任务:实际上在那之前合并一切,告诉git将maint~3标记为合并,即使它不合并,然后合并其余部分.神奇的是:
bash <master>$ git merge maint~4
bash <master>$ git merge -s ours maint~3
bash <master>$ git merge maint
Run Code Online (Sandbox Code Playgroud)
第一个命令将麻烦的maint提交之前的所有内容合并到master上.默认的合并日志消息将解释您正在合并"branch'maint'(早期部分)".
第二个命令合并麻烦的maint~3 commit,但是"-s ours"选项告诉git使用一个特殊的"合并策略",实际上,只需保留你要合并的树并忽略提交即可.你完全融合了.但是它仍然使用HEAD和maint~3作为父项进行新的合并提交,因此修订图现在表示maint~3被合并.所以实际上你可能也想使用-m选项'git merge'来解释maint~3 commit实际上被忽略了!
最后一个命令只是将其余的maint(maint~2..maint)合并到master中,这样你就可以再次同步了.
Ale*_* T. 34
IMHO, the most logical thing to do, is to merge everything, and then use git revert (commit_you_dont_want) to remove it.
Example:
git merge master
git revert 12345678
Run Code Online (Sandbox Code Playgroud)
If you have multiple "to-ignore" commits, or would like to edit revert message:
git merge master
git revert -n 123456
git revert -n abcdef
git commit -m "... Except commits 123456 and abcdef"
Run Code Online (Sandbox Code Playgroud)
Then your history may look like:
| ... Except 123456 and abcdef
|\ Merge branch 'master' into 'your_branch'
Run Code Online (Sandbox Code Playgroud)
If you have conflicts involving ONLY these "to-ignore" commits, you may use:
git merge master -X ours
Run Code Online (Sandbox Code Playgroud)
So your version will persist over the other one. Even without error messages, you may still "revert" those unwanted commits, because they may have other changes that did not conflict, and you still don't want them.
If you have conflicts envolving NOT ONLY the "to-ignore" commits, you should resolve them manually, and you'll probably have to resolve them again during reverting.
小智 6
听起来像'git cherry-pick'的经典案例 https://git-scm.com/docs/git-cherry-pick 它完全听起来像听起来像
| 归档时间: |
|
| 查看次数: |
50707 次 |
| 最近记录: |