git 常見反饋 記錄

有錯誤和改進的地方望留言,謝謝 : )html

順便推薦一下,git入門教程git

圖片描述


git status // 用 git status 查看一下當前狀態
# Untracked files: // 在 Untracked files 下,表示未被跟蹤,未跟蹤的文件意味着Git在以前的快照(提交)中沒有這些文件。
# (use "git add <file>..." to include in what will be committed) // 可使用 git add 命令添加到暫存區。
#
# readme.md編輯器


git add readme.md // 添加文件到(index) 暫存區,沒有反饋信息,Unix的哲學「沒有消息就是好消息」,說明添加成功。ide


$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: readme.md
只要在 Changes to be committed 這行下面的,就說明是已暫存狀態,但尚未提交。若是此時提交,那麼該文件此時此刻的版本將被留存在歷史記錄中。ui


$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: readme.md
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
#
# modified: benchmarks.rb
文件 benchmarks.rb 出如今 Changes not staged for commit 這行下面,說明已跟蹤文件的內容發生了變化,但尚未放到暫存區。要暫存此次更新,須要運行 git add 命令(這是個多功能命令,根據目標文件的狀態不一樣,此命令的效果也不一樣:能夠用它開始跟蹤新文件,或者把已跟蹤的文件放到暫存區,還能用於合併時把有衝突的文件標記爲已解決狀態等)。spa


編輯了一個文件,添加到暫存區,而後再編輯一下,會出現下面的狀況
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: README
# modified: benchmarks.rb
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
#
# modified: benchmarks.rb
實際上 Git 只不過暫存了你運行 git add 命令時的版本,若是如今提交,那麼提交的是第一次修改的版本,而非當前工做目錄中第二次修改的版本。因此,運行了 git add 以後又做了修訂的文件,須要從新運行 git add 把最新版本從新暫存起來。3d


git commit // 不加 -m 參數,這種方式會啓動文本編輯器以便輸入本次提交的說明。(默認會啓用 shell 的環境變量 $EDITOR 所指定的軟件,通常都是 vim 或 emacs。固然也能夠按照第一章介紹的方式,使用 git config --global core.editor 命令設定你喜歡的編輯軟件。)
若是啓用的是vim,打開後光標所在行就是輸入行,按 i 進入輸入模式(在光標所在行插入內容),輸入內容不用帶單引或雙引,按 Esc 退出輸入模式,按 Shift + : 進入命令模式,輸入 wq 保存並退出,也能夠不輸入內容,git 會默認顯示一段說明。
# 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)
#
# new file: README
# modified: benchmarks.rb
能夠看到,默認的提交消息包含最後一次運行 git status 的輸出,放在註釋行裏,另外開頭還有一空行,供你輸入提交說明。你徹底能夠去掉這些註釋行,不過留着也不要緊,多少能幫你回想起此次更新的內容有哪些。(若是以爲這還不夠,能夠用 -v 選項將修改差別的每一行都包含到註釋中來。)退出編輯器時,Git 會丟掉註釋行,將說明內容和本次更新提交到倉庫。


git commit -m 'add a file' // 提交一個被修改文件到庫,返回以下信息
[master (root-commit) cb926e7] wrote a readme file
1 file changed, 2 insertions(+) // 一個文件被修改,兩個插入
create mode 100644 readme.md // 生成 commit id 100644 這個id是id的前幾位,後面的沒顯示
提交後它會告訴你,當前是在哪一個分支(master)提交的,本次提交的完整 SHA-1 校驗和是什麼(463dc4f),以及在本次提交中,有多少文件修訂過,多少行添改和刪改過。


git diff readme.md // 當用 git diff 查看詳細信息,反饋以下信息
diff --git a/readme.md b/readme.md
index 46d49bf..9247db6 100644
--- a/readme.md // 原文件
+++ b/readme.md // 添加東西后的文件
@@ -1,2 +1,2 @@ // -1,2 被改變行1,共2行 +1,2在改行增長了東西,共2行
-Git is a version control system. // 被改變行
+Git is a distributed version control system. // 在該行添加了 distributed
Git is free software.


git status // 提交後再查看狀態
# On branch master
nothing to commit (working directory clean) // 這說明你如今的工做目錄至關乾淨。換句話說,全部已跟蹤文件在上次提交後都未被更改過。此外,上面的信息還代表,當前目錄下沒有出現任何處於未跟蹤的新文件,不然 Git 會在這裏列出來。最後,該命令還顯示了當前所在的分支是 master,這是默認的分支名稱,實際是能夠修改的。


我在 dev 分支上修改了一個文件,暫存,提交,再切換到另外一個分支
git checkout master // 切換到主分支
Switched to branch 'master'
Your branch is ahead of 'origin/master' by 1 commit // git會說,當前 master 分支比遠程的master分支要超前1個提交。


下面是合併兩個分支時,有衝突發生的時反饋以下形式信息

git merge feature // 合併叫 feature 的分支到當前分支上
Auto-merging readme.md // 自動合併 readme.md
CONFLICT (content): Merge conflict in readme.md // 合併時產生衝突
Automatic merge failed; fix conflicts and then commit the result. // 自動合併時失敗,解決衝突後提交。

git 會自動把衝突的地方用 <<<<<<<=======>>>>>>> 這樣的形式標出來
而且合併後的文件,表示爲添加的modifile文件,咱們要作的就是,把衝突文件改好,再 git add, git commit
HEAD 表明被合併分支
Git tracks changes of files.
<<<<<<< HEAD
Creating a new branch is quick & simple.
=======
Creating a new branch is quick AND simple.
>>>>>>> feature1

相關文章
相關標籤/搜索