2

通常,当工作目录干净时,我可以使用“git status”。输出如下所示:

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)

但是,如果修改了工作目录,“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:   body/chap1.tex
#
no changes added to commit (use "git add" and/or "git commit -a")

第二个结果没有显示我是否已将所有更改推送到远程分支。有时,当工作目录被修改时,我仍然想要第一个结果。在这种情况下如何获得它?

4

2 回答 2

1

这就是登台树的目的。您可以暂存您想要提交的工作,然后发送到 repo,如下所示:

git add path/to/your/file.php

这将暂存一个文件,然后将其存储在暂存树中(与您已提交的工作或未提交的工作分开),然后未来git status的调用将向您显示您已暂存的工作与您未提交的工作分开。这是 git 中的标准做法,可让您跟踪将要提交的内容。暂存是一种允许选择性提交的方法,但它应该服务于您的目的。

这是一个更好地解释暂存区域的链接:http: //git-scm.com/book/ch1-3.html

于 2013-07-10T13:48:52.357 回答
1

也许最简单的方法是存储当前的更改,检查然后弹出存储。像这样,

git stash
git status
git stash pop

这不适用于所有更改,例如新文件(因为git stash不会存储它们)。但是,我不得不说我没有重现您的问题:

ebg@taiyo(14)$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
ebg@taiyo(15)$ ed .gitignore 
1165
...
q
ebg@taiyo(16)$ git status
# On branch master
# Your branch is ahead of 'origin/master' 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:   .gitignore
#
no changes added to commit (use "git add" and/or "git commit -a")

在上面,相对的状态origin仍然出现。尽管如此,我的建议仍然有效:

ebg@taiyo(17)$ git stash
Saved working directory and index state WIP on master: b541ae8 Ignore 'SPOT Lang*' files
HEAD is now at b541ae8 Ignore 'SPOT Lang*' files
ebg@taiyo(18)$ git status
# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
ebg@taiyo(19)$ git stash pop
# On branch master
# Your branch is ahead of 'origin/master' 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:   .gitignore
#
no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (8ff02f7a27053ca7680b0a98048542fcbe2bb440)
于 2013-07-10T14:02:43.887 回答