如何在提交之前查看文件的更改?

Hou*_*man 12 git

我试过了 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$ 
Run Code Online (Sandbox Code Playgroud)

但它只是告诉我.htaccess已经改变了,但没有改变.我该如何实现这一目标?

更新: 在Aptana Studio中,可以提交任何内容之前查看更改.回到我的问题,在实际提交之前,必须有一种方法可以看到原始状态的差异.也许有一个不同的命令.

Joh*_*ter 18

确保你已经进行了一些更改.否则,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")
Run Code Online (Sandbox Code Playgroud)

暂存更改显示差异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.
Run Code Online (Sandbox Code Playgroud)

如果您只想在不提交的情况下查看diff,请使用git diff以查看未分级的更改,git diff --cached查看为提交暂存的更改,或git diff HEAD查看工作树中的分阶段和非分阶段更改.

更新:给你编辑,你真正想要的是git diff上面的衍生物.我不确定Aptana Studio的工作原理.它可能不遵循典型的命令行git流程.在命令行上,您将暂存更改,然后提交.以上git diff命令是您用来检查这些更改的命令.我通常将它们别名为git unstaged,git 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
Run Code Online (Sandbox Code Playgroud)


lri*_*eau 13

要查看跟踪文件中的所有差异但未暂存:

git diff
Run Code Online (Sandbox Code Playgroud)

要么

git diff path/to/a/given/file
Run Code Online (Sandbox Code Playgroud)

仅查看文件的差异.您还可以在项目的给定子目录中看到diff:

git diff path/to/a/dir/
Run Code Online (Sandbox Code Playgroud)

如果您已经进行了更改git add,则可以看到您上传的补丁

git diff --staged
Run Code Online (Sandbox Code Playgroud)

您也可以指定路径--staged.