使用"commit --cleanup=whitespace"和"rebase --interactive"命令来操作git。

15

我想在创建/编辑提交消息时始终使用--cleanup=whitespace(以允许初始“#”)。不幸的是,我找不到适当的设置来放置在~/.gitconfig中;这个设置不起作用:

[commit]
    cleanup = whitespace

对于普通的提交,我添加了--cleanup=whitespace到我的主要提交别名,但是我不知道如何将此选项传递给git rebase --interactive,以便我可以重新编辑和合并提交并使用我的首选清理方法。


我也不知道,而且我也需要,所以就+1吧。 - route
请问您能否更具体一些? - Dahir Warsame
这里可能会对新的git commit --cleanup=scissors模式感兴趣。请参见下面我的回答 - VonC
3个回答

8
git 1.8.2 中,他们添加了我试图使用的设置:

可以通过设置配置变量commit.cleanup为'whitespace'来告诉"git commit"使用--cleanup=whitespace。

同时,我只是在一个#前面添加了一个空格...

另外,在 .gitconfig 中在 [core] 下设置 commentChar = ";" 对于编写包含以 # 开始的标题的 Markdown 格式的提交消息非常有用:https://git-scm.com/docs/git-config#Documentation/git-config.txt-corecommentChar - 0 _

0
  1. 打开位于项目文件夹中的 .git/config 文件。
  2. 在该文件中,您会找到一个名为 [core] 的部分。例如,对我来说它看起来像这样:
    [core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
    
    在该部分末尾添加 commentChar = ";"(或选择其他字符而不是 ;,如果您有其他偏好)。您可以在此处阅读更多关于此设置的信息:https://git-scm.com/docs/git-config#Documentation/git-config.txt-corecommentChar。对我来说,该部分现在看起来像这样:
    [core]
        repositoryformatversion = 0
        filemode = false
        bare = false
        logallrefupdates = true
        symlinks = false
        ignorecase = true
        commentChar = ";"
    
  3. 现在,进行变基操作。例如:
    $ git rebase -i HEAD~4
    
  4. 对我来说,我选择重写我的提交消息:
    r ca9bb66 #77204 Change formatting in ActiveFundOrderSubstateHandler.cs
    r 7879f86 #77204 Rename class
    r ff1adc3 #77204 Formatting change
    r 9df6615 #77294 Fix formatting
    
  5. 现在,我可以更改我的提交消息,同时保留其中的 #

-1

你是指像这样的吗?

[alias]
    rec = rebase --interactive

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接