Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git:修改工作目录时,如何检查本地分支是否在远程分支之前?_Git_Git Remote_Remote Branch - Fatal编程技术网

Git:修改工作目录时,如何检查本地分支是否在远程分支之前?

Git:修改工作目录时,如何检查本地分支是否在远程分支之前?,git,git-remote,remote-branch,Git,Git Remote,Remote Branch,通常,当工作目录是干净的时,我可以使用“git status”。输出如下所示: # On branch master # Your branch is ahead of 'origin/master' by 1 commit. # nothing to commit (working directory clean) 但是,如果修改了工作目录,“git status”输出: 分支主机上的# #未为提交而暂存的更改: #(使用“git add…”更新将提交的内容) #(使用“git签出--…”放

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

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
nothing to commit (working directory clean)
但是,如果修改了工作目录,“git status”输出:

分支主机上的
#
#未为提交而暂存的更改:
#(使用“git add…”更新将提交的内容)
#(使用“git签出--…”放弃工作目录中的更改)
#
#修改:主体/chap1.tex
#
未向提交添加任何更改(使用“git add”和/或“git commit-a”)

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

这是登台树的目的。您可以将要提交的工作分段,然后发送到回购协议,如下所示:

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

以下链接可以更好地解释暂存区域:

也许最简单的方法是隐藏当前更改,检查并弹出隐藏内容。因此,

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")

我正在Windows系统上使用msys git。这有点不同。
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")
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)