2013-02-27 103 views
0

我想修改在提交我剛纔提出的提交信息,所以我試圖做的事:爲什麼我得到一個錯誤,當我嘗試git的承諾--amend

git commit --amend 

(我通常做),但我得到了一個錯誤:

Unable to find modified files; please check git status 

現在,這是奇怪的,從提交,因爲我不想要添加/刪除文件,我只是想改變的消息,所以它不應該也罷我有修改文件或沒有。

任何人都可以解釋這個錯誤信息(理想情況下,我怎麼能通過它)?

*編輯*

Mellowcandle要求我的git的狀態;這裏是(或多或少):

# On branch some_branch 
# Your branch is ahead of 'origin/some_branch' by 1 commit. 
# 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: static/js/someFile.js 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# some/other/file 
# yet/another/file 

*編輯#2 *

當我嘗試git rebase -i(與reword)出現同樣的問題。

*編輯#3 *

這裏有一個git config --list(略匿名)的輸出,通過GoZoner的要求:

user.name=My Name 
[email protected] 
push.default=upstream 
core.repositoryformatversion=0 
core.filemode=true 
core.bare=false 
core.logallrefupdates=true 
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/* 
[email protected]:someGitHubAccount/Apps.git 
branch.master.remote=origin 
branch.master.merge=refs/heads/master 
branch.deploy.remote=origin 
branch.deploy.merge=refs/heads/deploy 
...*more branches that look similar* 
+2

請發佈git status – stdcall 2013-02-27 18:02:08

+1

最後一次提交是什麼? (使用'git log HEAD^..'來查看它)。它是一個合併提交?也許你想修改_before_提交? – 2013-02-27 18:13:16

+0

您已修改文件,因此'git commit --amend'不會更改上次提交。如果狀態是乾淨的,只能這樣做。錯誤信息令人困惑,我相信最近清理了。那是什麼版本的git? – vonbrand 2013-02-27 18:15:42

回答

2

檢查您是否沒有在提交時觸發的自定義掛鉤。

1

git commit --amend將工作就像git commit只是將回收您舊提交。所以這意味着它會預期實際上索引中會有一些變化,隨時可以承諾。

所以,如果你想要你的someFile.js被包括在內,首先運行git add static/js/someFile.js。如果您還想跟蹤未跟蹤文件,請使用git add some/other/file添加該文件。

+1

您可以在樹中沒有任何更改的情況下修改提交。 – 2013-02-27 18:12:45

+0

@MichaëlWitrant呃,是的,你說得對。 – poke 2013-02-27 18:20:32

1

嘗試git commit --amend --only,如果不起作用,那就試試git stash; git commit --amend ; git stash pop。我不確定你在這裏的狀態。

+0

無論是修改前還是修改都沒有問題;我在這兩種情況下得到了相同的錯誤消息 – machineghost 2013-02-27 19:16:49

2

或者,你可能只是做對當前的父的互動變基承諾

git rebase -i head~ 

,然後選擇reword選項更改提交信息。

+0

我熟悉'git rebase -i',但我真的認爲'git commit --amend'應該在這些情況下工作,所以在我完全放棄命令之前(理想情況下)想知道發生了什麼。 – machineghost 2013-02-27 19:17:48

+0

這有點遲來,但我又遇到了同樣的問題,所以我嘗試了你的方法。首先'head〜'應該是'HEAD〜',對吧?其次,即使當我這樣做時,rebase編輯器按預期彈出,但是當我用'reword'保存文件時,我得到了相同的命令行輸出:'無法找到修改的文件;請檢查混帳狀態 已成功重新更新並更新了參考號/頭/主.' – machineghost 2013-04-23 21:02:24

+0

在我的情況下,(OS X)'head'不區分大小寫。 – Abizern 2013-04-23 21:23:08

1

git stash。然後做git commit --amend。 之後,做git stash pop

+1

混帳,得到或得到? – CharlesB 2013-02-27 18:38:58

+1

「got」是「git」的過去式,顯然,「get」是未來時態。 :-) – torek 2013-02-27 20:04:51

+2

!:#*#&手機自動更正 – stdcall 2013-02-27 22:01:59

1

適用於我,無論是否有修改過的未跟蹤文件。

$ echo 'a' > a; git add -A; git commit -m 'a' 
$ echo 'b' > b; git add -A; git commit -m 'b' 

$ git log --oneline 
63f2dd1 b 
a0b364a a 
$ git commit --amend 
$ git log --oneline 
d4cdeb7 bxx   # changed the commit message 
a0b364a a 

$ ed a # edit 'a' 
$ git status 
# On branch master 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: a 
# 
no changes added to commit (use "git add" and/or "git commit -a") 

$ git commit --amend 
$ git log --oneline 
2d20e6e bxxyy   # changed the commit message again 
a0b364a a 

$ mkdir foo; echo 'c' > foo/c 
$ git status 
# On branch master 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: a 
# 
# Untracked files: 
# (use "git add <file>..." to include in what will be committed) 
# 
# foo/ 
no changes added to commit (use "git add" and/or "git commit -a") 

$ git commit --amend 
[email protected](31)$ git log --oneline 
09c1b26 bxxyyzz 
a0b364a a 
+0

是的,它也用於在不同的機器上工作。問題的關鍵在於試圖確定爲什麼它不能在這臺機器上工作。 – machineghost 2013-04-23 22:34:16

+0

我明白了。你做了一個'git config --list'並尋找奇怪的東西嗎? – GoZoner 2013-04-23 23:07:50

+0

我已將它添加到答案中;沒有什麼東西看起來很奇怪(雖然我不會聲稱自己是Git配置專家......) – machineghost 2013-04-24 00:22:37

相關問題