[譯]git status


git status

git status命令能展示工作目錄和stage區的狀態. 使用他你能看到那些修改被staged到了, 哪些沒有, 哪些文件沒有被Git tracked到. git status不顯示已經commit到項目歷史中去的信息. 看項目歷史的信息要使用git log.

 

用法

git status

列出哪些文件被staged了, 哪些文件沒有被staged到, 哪些文件沒有被tracked到.

 

討論

git status相對來說是一個簡單的命令. 他簡單的展示狀態信息. 輸出的內容分為3個分類/組

# On branch master
# Changes to be committed:  (已經在stage區, 等待添加到HEAD中的文件)
# (use "git reset HEAD <file>..." to unstage)
#
#modified: hello.py
#
# Changes not staged for commit: (有修改, 但是沒有被添加到stage區的文件)
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
#modified: main.py
#
# Untracked files:(沒有tracked過的文件, 即從沒有add過的文件)
# (use "git add <file>..." to include in what will be committed)
#
#hello.pyc

 

 

Ignoring Files

沒有tracked的文件分為兩類. 一是已經被放在工作目錄下但是還沒有add的, 另一類是一些編譯了的程序文件(如 .pyc .obj .exe等). 一旦這些我們不想add的文件一多起來, git status的輸出簡直沒法看, 一大堆的狀態信息怎么看? 

 

基於這個原因. Git讓我們能在一個特殊的文件.gitignore中把我們要忽略的文件放在其中. 每一個想忽略的文件應該獨占一行, *這個符號可以作為通配符使用. 例如在項目根目錄下的.gitignore文件中加入下面內容能阻止.pyc文件出現在git status中:

*.pyc

 

 

例子

在每次commit之前先使用git status檢查文件狀態是一個很好的習慣, 這樣能防止你不小心commit了你不想commit的東西. 下面的例子展示stage 前后的狀態, 並最后commit一個快照.

# Edit hello.py
git status
# hello.py is listed under "Changes not staged for commit"
git add hello.py
git status
# hello.py is listed under "Changes to be committed"
git commit
git status
# nothing to commit (working directory clean)

第一個狀態輸出顯示了這個文件沒有staged. git add將影響第二個git status的輸出, 最后一個git status告訴我們沒有什么能commit了—工作目錄已經和最近的commit相匹配了. 有些命令 (如, git merge) 要求工作目錄是clean狀態, 這樣就不會不小心覆蓋更新了.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM