保持你的git log意义

git-logo_thumb2.

在此博客文章中,我们将看看我们如何将多个致力于单个宣告合并到一个单一的帖子中,其目标是在GIT日志中减少喋喋不休的目标。这种技术通常被称为 挤压.

何时使用它

在新的功能(用户故事)上工作时,最好经常进行练习。这使您可以选择始终扭转返回安全位置,而不会丢失大量工作。但是一旦您对远程存储库的更改提交了更改,就会在一个/少数有意义的提交中获取您的工作的Quintessence会很好。通常,所有那些小安全挂钩都不在服务器存储库中有用,甚至可能会损害通过日志读取的流程并获得大图片。

它是如何完成的

您可以根据要突出的提交计数或提交ID rencase rensue:

git rebase. -i 003ee6c6f34516ad325a72d430e5a269e470b4d3

或者,您可以设置要绑定的提交的计数:

git rebase. -i HEAD~4

在这里,我们告诉Git rebase最后四个提交。执行命令后,您的Commit消息选择的编辑器将弹出:

pick 5629556 Adds second paragraph
pick 56ea060 Adds third paragraph
pick 892c090 Adds final paragraph

# Rebase 003ee6c..892c090 onto 003ee6c
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "壁球", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

只需更改命令即可 壁球 IE。 s 并且您的提交将被压制成一个提交。注意您要选择挤压的起点:

pick 5629556 Adds second paragraph
squash 56ea060 Adds third paragraph
squash 892c090 Adds final paragraph

# Rebase 003ee6c..892c090 onto 003ee6c
#
# Commands:
#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "壁球", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out

合并您的提交消息i.e.允许您编辑与提交关联的消息:

Some very meaningful merge commit message comes here.

# This is a combination of 3 commits.
# The first commit's message is:
Adds second paragraph

# This is the 2nd commit message:

Adds third paragraph

# This is the 3rd commit message:

Adds final paragraph

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# rebase in progress; onto 003ee6c
# You are currently editing a commit while rebasing branch 'master' on '003ee6c'.
#
# Changes to be committed:
#    modified:   someFile.txt
#

何时从这种技术留下手指

不要绑定存储库中存在的提交。

使用rebase,您正在更改git存储库的历史记录。如果你在历史上这样做,你发表的历史,其他人正在使用..让我们说你不会被许多友好的话语获得奖励。正如你将打破他们正在使用的历史,以便在导致大烂摊子上工作。所以 仅将rebasing应用于本地存储库 你还没有发布。如果您是存储库唯一的宣言(并且没有任何其他副本与...)的例外情况是例外。

结论

使用 git rebase. 使您可以修改提交历史记录,并使它更可读,更少的笨重。这有助于您和您的共同提交者具有有意义的提交有意义的日志历史记录。此外,它允许开发人员在编码时经常提交到本地存储库,并且如果一种方法已经证明徒劳无功,可以随时返回。所有都没有乱丢项目的日志历史记录,并以大量的非有意义的日志条目结束。

然而,从来没有在公共历史上恢复,因为这可能导致流泪和强烈的讨论。

参考:

//help.github.com/articles/about-git-rebase/

http://www.git-scm.com/book/en/v2/Git-Branching-Rebasing

Updated: