47

私が試してみましたgit commit -v

ubuntu@ip:~/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")
ubuntu@ip:~/agile$ 

しかし、それは私が変わったことを示しているだけで.htaccess、何が変わったわけではありません. どうすればこれを達成できますか?

更新: Aptana Studio では、何かをコミットする前に変更を確認できます。私の質問に戻ると、実際にコミットする前に、元の状態との違いを確認する方法が必要です。そのための別のコマンドがあるかもしれません。

4

2 に答える 2

55

追跡されているがステージングされていないファイルのすべての差分を表示するには:

git diff

また

git diff path/to/a/given/file

ファイルの差分のみを表示します。プロジェクトの特定のサブディレクトリで差分を確認することもできます。

git diff path/to/a/dir/

で変更をすでにステージングしている場合は、git addステージングしたパッチを確認できます。

git diff --staged

でパスを指定することもできます--staged

于 2012-12-09T13:40:56.887 に答える
35

いくつかの変更をステージングしたことを確認してください。それ以外の場合は、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ます。

:: 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 unstaged,としてエイリアスしgit stagedgit bothこれを my に追加します~/.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
于 2012-12-09T11:57:10.027 に答える