2012-12-09 141 views
5

我試圖git commit -v如何在提交之前查看文件的更改?

[email protected]:~/agile$ git commit -v 
# 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: .htaccess 
# 
no changes added to commit (use "git add" and/or "git commit -a") 
[email protected]:~/agile$ 

但它只是顯示我.htaccess已經改變,但不是發生了什麼變化。我如何實現這一目標?

更新: 在集錦工作室就可以看到你承諾什麼前的變化。回到我的問題,在實際提交之前,必須有辦法看到與原始狀態的差異。也許有一個不同的命令。

回答

10

確保您已經進行了一些更改。否則,git commit -v會顯示與您發佈的內容類似的內容,但不會執行任何操作。您可以使用git add手動分階段進行更改,或者如果這些文件已經過版本控制,則可以使用git commit -a -v分階段並提交更改。

例如:

$ echo "more foo" >> foo.txt 
$ git commit -v 
# 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: foo.txt 
# 
no changes added to commit (use "git add" and/or "git commit -a") 

舞臺的變化顯示了git commit -v的DIFF:

:: git add foo.txt 
:: GIT_EDITOR=cat git commit -v 

# Please enter the commit message for your changes. Lines starting 
# with '#' will be ignored, and an empty message aborts the commit. 
# On branch master 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# modified: foo.txt 
# 
diff --git a/foo.txt b/foo.txt 
index 257cc56..a521556 100644 
--- a/foo.txt 
+++ b/foo.txt 
@@ -1 +1,2 @@ 
foo 
+more foo 
Aborting commit due to empty commit message. 

如果你只是想看到的差異而不提交,使用git diff看不分階段的變化,git diff --cached到查看爲提交進行的更改,或git diff HEAD以查看工作樹中的暫存和未暫存更改。

UPDATE:給出你的編輯,你真正想要的是git diff以上的衍生產品。我不確定Aptana Studio如何工作。它可能不遵循典型的命令行git流程。在命令行上,您可以進行更改,然後進行提交。上面的git diff命令是您用來檢查這些更改的命令。我通常爲git unstagedgit staged,並git both加入這個我~/.gitconfig別名他們:

[alias] 
    # show difference between working tree and the index 
    unstaged = diff 

    # show difference between the HEAD and the index 
    staged = diff --cached 

    # show staged and unstaged changes (what would be committed with "git commit -a") 
    both = diff HEAD 
+0

+1是的。 'git diff .htaccess'做我想達到的。謝謝 :) – Houman

6

要查看跟蹤的文件中的所有差異,但沒有上演:

git diff 

git diff path/to/a/given/file 

只能查看文件的差異。你也可以看到差異在您的項目中給定的子目錄:

git diff path/to/a/dir/ 

如果您已經上演着git add的變化,你可以看到你有

git diff --staged 

上演什麼補丁你也可以用--staged指定路徑。

相關問題