git rebase -i HEAD~7 - 在编辑器中只显示"noop"

Rya*_*ong 12 git version-control rebase

我试图将一个在HEAD的提交压缩成一个返回的提交.git rebase -i HEAD~7然而,当我跑步时,我noop在编辑器中只出现了一个!我完全不知道这是如何工作的.

在我第一次体验之后cleanup,我正在创建一个我创建的分支()(checkout -b cleanup ...在我找到的SHA1上使用reflog)rebase,我不小心删除了所有这些提交; 重点是,我不确定分支的父母是什么(如果重要的话,这里).

我只是试图做我已经阅读过很多次的内容:我想稍微修改一些不是最近提交的提交代码.当我达到这一点时,无论是"挤压"还是仅仅修改它,我都不知道.

我也在STDOUT上看到这个,因为编辑器在运行上面显示的rebase命令后启动:

$ git rebase -i HEAD~7
usage: git rev-list [OPTION] <commit-id>... [ -- paths... ]
  limiting output:
    --max-count=<n>
    ...
Run Code Online (Sandbox Code Playgroud)

除了HEAD~7引用之外,我还尝试指定整个SHA1,并为本地和远程分支指定不同的refspec.一切都相同......

我错过了什么?谢谢你的帮助!


编辑:

$ git log --oneline HEAD~7..HEAD
d0fd20e temp Fix resume_cities table
ea2ffdf Fix db/seeds.rb to reflect recent database structure modifications
dbd2b8b Add several models/scaffolds that go along with the Geonames tables
9759091 Fix name of the ResumeSkill model file.
3fc3134 Added the SHA1 for the previous commit to the comments on the migration, to help link back to that.
bacbeb2 Consolidate database migrations! READ ME!
0c49a57 Moved back to gem versions of linkedin, omniauth, and twitter
Run Code Online (Sandbox Code Playgroud)

这是bacbeb2我想要修改的提交d0fd20e


每@MarkLongair的推荐下,我加入set -x/usr/lib/git-core/git-rebase--interactive和看到如下奇怪的输出:

$ git rebase -i HEAD~7

[... output muted for brevity, see the full output, here: http://gist.github.com/1163118]
+ read -r shortsha1 rest
+ sed -n s/^>//p
+ git rev-list --no-merges --cherry-pick --pretty=oneline --abbrev-commit --abbrev=7 --reverse --left-right --topo-order 2c51946812a198ca908ebcad2308e4b8274624b3...d0e9ff6d9c1f8bc374856ca2a84ad52d6013b5bf
usage: git rev-list [OPTION] <commit-id>... [ -- paths... ]
  limiting output:
    --max-count=<n>
    --max-age=<epoch>
    --min-age=<epoch>
    --sparse
    --no-merges
    --remove-empty
    --all
    --branches
    --tags
    --remotes
    --stdin
    --quiet
  ordering output:
    --topo-order
    --date-order
    --reverse
  formatting output:
    --parents
    --children
    --objects | --objects-edge
    --unpacked
    --header | --pretty
    --abbrev=<n> | --no-abbrev
    --abbrev-commit
    --left-right
  special purpose:
    --bisect
    --bisect-vars
    --bisect-all
+ test t = 
+ test -s /home/ryan/Projects/social-jobs/.git/rebase-merge/git-rebase-todo
+ echo noop
[...]
Run Code Online (Sandbox Code Playgroud)

我说'奇怪的输出',因为如果我rev-list直接从我的shell 运行命令,它按预期工作:

$ git rev-list --no-merges --cherry-pick --pretty=oneline --abbrev-commit --abbrev=7 --reverse --left-right --topo-order 2c51946812a198ca908ebcad2308e4b8274624b3...d0e9ff6d9c1f8bc374856ca2a84ad52d6013b5bf
>0c49a57 Moved back to gem versions of linkedin, omniauth, and twitter
>bacbeb2 Consolidate database migrations! READ ME!
>3fc3134 Added the SHA1 for the previous commit to the comments on the migration, to help link back to that.
>9759091 Fix name of the ResumeSkill model file.
>dbd2b8b Add several models/scaffolds that go along with the Geonames tables
>ea2ffdf Fix db/seeds.rb to reflect recent database structure modifications
>d0e9ff6 !temp Fix resume_cities table !temp
Run Code Online (Sandbox Code Playgroud)

Mar*_*air 12

更新:在我的答案结束时有这种行为的解释,但我已经在这里留下了调试建议,以防它们对任何人都有用.


我不确定我在这里有一个真正的答案,但我会根据我的理解解释发生了什么.当作为调用git rebase -i HEAD~7,混帐应该只输出noop.git/rebase-merge/git-rebase-todo该文件是否为空或不存在.我们知道这不是权限问题,因为该文件(包含"noop"和注释行)已成功创建.您git rev-list在终端上看到错误的事实也表明问题实际上是由于如何git rev-list调用.在git v1.7.4.1中,使用您引用的命令行,应该从以下内容中找到要包含的提交列表:

git rev-list --no-merges --cherry-pick --pretty=oneline --abbrev-commit \
    --abbrev=7 --reverse --left-right --topo-order HEAD~7...HEAD
Run Code Online (Sandbox Code Playgroud)

请注意,这与手册页(git log <upstream>..HEAD)的建议略有不同,因为范围使用...而不是..

我猜,因为你看到一个错误git rev-list,这是有问题的命令.你可以尝试一下,看看输出是什么?如果这似乎有效,那么我怀疑有一个早期错误导致此命令行格式错误.由于交互式rebase是作为shell脚本实现的,因此您可以通过编辑脚本sudo editor /usr/lib/git-core/git-rebase--interactiveset -x在顶部添加来轻松地对此进行调查,例如:

#!/bin/sh
set -x
#
# Copyright (c) 2006 Johannes E. Schindelin

# SHORT DESCRIPTION
[...]
Run Code Online (Sandbox Code Playgroud)

然后,如果您尝试运行git rebase -i HEAD~7,您应该看到脚本正在运行的每个命令,并且可能会看到git rev-list调用有什么问题.

我希望有一些帮助.


更新:原来,这里的问题是提问已IFS设置为只包括标签和换行,而不是空格,制表符和换行的默认.

这会导致行git-rebase--interactive开头出现问题:

git rev-list $MERGES_OPTION --pretty=oneline [...]
Run Code Online (Sandbox Code Playgroud)

...因为MERGES_OPTION设置为--no-merges --cherry-pick.使用默认值IFS(包括空格),将在替换变量后将其拆分为两个参数.但是,IFS如果不包含空格,--no-merges --cherry-pick则会将其解释为单个且明显未知的参数,从而导致git rev-list在脚本中传递用法消息和空输出.

一个很好的拼图:)


Rya*_*ong 7

此问题是由我的.bashrc 设置IFS 引起的:

# remove the space character from IFS
# (http://www.dwheeler.com/essays/fixing-unix-linux-filenames.html#IFS)
IFS="`printf '\n\t'`"
Run Code Online (Sandbox Code Playgroud)

我根本不记得为什么我把它放在那里.我确定它与"修复UNIX/Linux文件名"有关,如我所包含的URL所示.不知道.

尽管如此,我删除了那句话并且:POOF!没问题!

非常感谢@MarkLongair的帮助!

  • 也许你应该在git邮件列表中询问:git@vger.kernel.org. (2认同)