2013-07-10 87 views
2

通常,當工作目錄乾淨時,我可以使用「git status」。輸出看起來像:Git:當工作目錄被修改時如何檢查本地分支是否在遠程分支之前?

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

但是,如果工作目錄進行修改,「混帳地位」輸出:

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

第二個結果不顯示,如果我已經推動所有更改遠程分支機構。有時,當工作目錄被修改時,我仍然需要第一個結果。如何在這種情況下獲得它?

回答

1

這是分段樹的目的。你可以階段,你要提交,然後發送到回購爲隨後的工作:

git add path/to/your/file.php 

這將上演一個文件,這樣它就會從您提交的工作或你未提交保存在臨時樹(獨立工作),那麼未來git status調用將向您顯示您已完成的工作與您未提交的工作分開。這是git的標準做法,可以讓你跟蹤你將要提交的內容。分段是一種允許選擇性提交的方法,但它應該服務於你的目的。

這裏是一個鏈接,更好地解釋了臨時區域: http://git-scm.com/book/ch1-3.html

1

也許最簡單的將是藏匿的電流變化,檢查然後彈出藏匿。因此,

git stash 
git status 
git stash pop 

這不會對所有的變化,比如新的文件(因爲git stash不會藏匿他們)工作。但是,我不得不說,我不是複製您的問題:

[email protected](14)$ git status 
# On branch master 
# Your branch is ahead of 'origin/master' by 1 commit. 
# 
nothing to commit (working directory clean) 
[email protected](15)$ ed .gitignore 
1165 
... 
q 
[email protected](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狀態。不過,我的建議工程:

[email protected](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 
[email protected](18)$ git status 
# On branch master 
# Your branch is ahead of 'origin/master' by 1 commit. 
# 
nothing to commit (working directory clean) 
[email protected](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/[email protected]{0} (8ff02f7a27053ca7680b0a98048542fcbe2bb440) 
+0

我在Windows系統上使用msys-git。它有點不同。 – river6

相關問題