本文介绍了合并GIT分支而无需提交日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,当我使用GIT时,我会为每个作业创建一个分支,并在完成之前进行各种提交。然后,我与主分支合并,并推向上游。我很可能在任何时候都有几个分支机构,并且在它们发生中断时也可以在它们之间轻弹。



但是其中大部分提交都只是保存点,即在事物的宏伟计划中不那么重要。所以当我合并分支时,如果分支日志没有与主日志合并,我会喜欢它。



有没有办法只为下面的提交g合并日志消息(而不是提交c或e)?

  a [master] 
|
b(创建分支'job')
| \
| \
| c
| |
d e
| |
fg(下一步是将'job'分支与'master'合并)


解决方案

有,但这是无稽之谈。你为什么想这样做?你会失去所有的分支历史和信息。



你可以使用g的提交信息进行合并提交,然后用 - 第一个浏览历史记录-brent 选项。



如果您真的想从分支中删除历史记录,请使用 git merge --squash ,我不推荐它,但
$ b

编辑

如果你不喜欢,因为你不认为你的历史很干净,你可以使用git的:



您可以追溯编辑旧版本,并从您现有的分支创建新的提交(实际上将其重写)。它允许你重新提交提交消息,分割提交,压缩提交到单个提交,重新提交提交等。



你应该只使用rebasing当你还没有发布你的分支(即它只是一个私人分支),因为它会给其他开发者头痛,并且如果有人继续在旧分支之前工作,可能会导致合并问题。


Currently when I'm using GIT I create a branch for each job and make various commits before I'm finished. I then merge back with my master branch and push upstream. I'm likely to have several branches at any one time and also flick between them mid-job as things crop up.

But most of these commits are just save points, i.e. not that important in the grand scheme of things. So when I merge the branch, I'd like it if the branch logs didn't merge with the master logs.

Is there a way to just merge the log message for commit g below (and not commits c or e)?

a [master]
|
b (create branch 'job')
|\
| \
|  c
|  |
d  e
|  |
f  g (next step is to merge 'job' branch with 'master')
解决方案

there is, but it is nonsense. why do you want to do that? you'll lose all branch history and information.

you could use g's commit message for your merge commit and then browse history with the --first-parent option.

if you really want to lose history from your branch use git merge --squash, i do not recommend it though

edit

in case you are not happy because you do not consider your history very clean, you can use git's rebase feature:

you can retroactively edit old and create new commits from your existing branch (in effect rewriting it). it allows you to reword commit messages, split commits, squash commits into a single commit, re-order commits, etc.

you should only use rebasing when you haven't published your branch (i.e. it is only a private branch), because it will give other developers headache and could cause merge problems later on, if someone kept working on the old (before rebased) branch.

这篇关于合并GIT分支而无需提交日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 21:26