简体   繁体   English

在没有提交日志的情况下合并 GIT 分支

[英]Merge GIT branch without commit log

Currently when I'm using GIT I create a branch for each job and make various commits before I'm finished.目前,当我使用 GIT 时,我为每个作业创建一个分支,并在完成之前进行各种提交。 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, ie 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')

I consider merge --squash extremely useful when I use a "branch per feature" approach.当我使用“每个功能分支”的方法时,我认为merge --squash非常有用。 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.我真的希望再也看不到那段历史,而不仅仅是能够跳过它。

When the commits go to code review, it is important not to create extra commits.当提交进入代码审查时,重要的是不要创建额外的提交。

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 commits 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 (ie 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 之前)分支上工作,它会让其他开发人员头疼并可能在以后导致合并问题.

As mentioned in " Trimming GIT Checkins/Squashing GIT History ", if your commits c and e were done with a comment prefixed with fixup!如“ 修剪 GIT 签入/压缩 GIT 历史记录”中所述,如果您的提交ce是使用带有fixup!前缀的注释完成的fixup! , then the rebase --interactive --autosquash (git1.7+, February 2010) can do exactly what you are after. ,然后rebase --interactive --autosquash (git1.7+,2010 年 2 月)可以完全满足您的要求。

with the fixup!fixup! directive, you could keep that squashing "invisible" in the commit message, while still benefiting from the automatic commit reordering with the --autosquash option.指令,您可以在提交消息中保持压缩“不可见”,同时仍然受益于使用 --autosquash 选项的自动提交重新排序。

To commit with a fixup!提交一个fixup! prefix, you can define the alias前缀,可以定义别名

[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, ie not that important in the grand scheme of things".然后fixup别名将应用于那些“提交(哪些)只是保存点,即在事物的宏伟计划中并不那么重要”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM