在没有提交日志的情况下合并 GIT 分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4123077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Merge GIT branch without commit log
提问by Adam
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.
目前,当我使用 GIT 时,我为每个作业创建一个分支,并在完成之前进行各种提交。然后我与我的主分支合并并向上游推送。我很可能在任何时候都有几个分支,并且随着事情的出现,在工作中途在它们之间轻弹。
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)?
有没有办法只合并下面提交 g 的日志消息(而不是提交 c 或 e)?
a [master]
|
b (create branch 'job')
|\
| \
| c
| |
d e
| |
f g (next step is to merge 'job' branch with 'master')
采纳答案by knittl
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.
您可以使用 g 的提交消息进行合并提交,然后使用该--first-parent
选项浏览历史记录。
if you really want to lose history from your branch use git merge --squash
, i do not recommend it though
如果你真的想从你的分支使用中丢失历史git merge --squash
,我不推荐它
edit
编辑
in case you are not happy because you do not consider your history very clean, you can use git's rebase feature:
如果您不满意,因为您认为您的历史记录不是很干净,您可以使用 git 的rebase 功能:
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.
你应该只在你还没有发布你的分支(即它只是一个私有分支)时才使用 rebase,因为如果有人继续在旧的(rebase 之前)分支上工作,它会让其他开发人员头疼并可能在以后导致合并问题.
回答by Ellioh
I consider merge --squash extremely useful when I use a "branch per feature" approach. My commit history in temporary branches is a complete garbage, absolutely meaningless. And I really want to be unable to see that history anymore, not just to be able to skip it.
当我使用“每个功能分支”的方法时,我认为 merge --squash 非常有用。我在临时分支中的提交历史完全是垃圾,完全没有意义。我真的希望再也看不到那段历史,而不仅仅是能够跳过它。
When the commits go to code review, it is important not to create extra commits.
当提交进入代码时,重要的是不要创建额外的提交。
回答by VonC
As mentioned in "Trimming GIT Checkins/Squashing GIT History", if your commits c
and e
were done with a comment prefixed with fixup!
, then the rebase --interactive --autosquash
(git1.7+, February 2010) can do exactlywhat you are after.
如“修剪 GIT 签入/压缩 GIT 历史记录”中所述,如果您的提交c
并e
使用前缀为 的注释完成fixup!
,那么rebase --interactive --autosquash
(git1.7+, 2010 年 2 月) 可以完全满足您的要求。
with the
fixup!
directive, you could keep that squashing "invisible" in the commit message, while still benefiting from the automatic commit reordering with the --autosquash option.
使用该
fixup!
指令,您可以在提交消息中保持压缩“不可见”,同时仍然受益于使用 --autosquash 选项的自动提交重新排序。
To commit with a fixup!
prefix, you can define the alias
要使用fixup!
前缀提交,您可以定义别名
[alias]
fixup = !sh -c 'git commit -m \"fixup! $(git log -1 --format='\''%s'\'' $@)\"' -
squash = !sh -c 'git commit -m \"squash! $(git log -1 --format='\''%s'\'' $@)\"' -
The fixup
alias would then apply for those "commits (which) are just save points, i.e. not that important in the grand scheme of things".
然后fixup
别名将应用于那些“提交(哪些)只是保存点,即在事物的宏伟计划中并不那么重要”。