1. 程式人生 > >1git命令的使用 檢視git倉庫狀態 新增檔案到git跟蹤 git提交 檢視git分支 檢視git倉庫日誌資訊 切換g

1git命令的使用 檢視git倉庫狀態 新增檔案到git跟蹤 git提交 檢視git分支 檢視git倉庫日誌資訊 切換g

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow

也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!

               
1新建一個儲存git的資料夾,命令是:
[email protected]:~$ mkdir gitfolder

  
2初始化一個git倉庫,命令是:
[email protected]:~$cd gitfolder/
[email protected]:~/gitfolder$ls
[email protected]:~/gitfolder$git init
初始化空的 Git版本庫於 /home/toto/gitfolder/.git/
  
注意:如果是第一次使用git,還要對git對進行如下配置
git config --global user.email "[email protected]"
git config --global user.name "tuzuoquan"

  
3 顯示倉庫內的所有內容,命令是:
[email protected]:~/gitfolder$ll
總用量 12
drwxrwxr-x 3 toto toto 4096 1122 23:12 ./
drwxr-xr-x 31 toto toto 4096 1122 23:09 ../
drwxrwxr-x 7 toto toto 4096 1122 23:12 .git/

  
4 檢視git倉庫狀態
[email protected]
:~/gitfolder$ git status
位於分支 master
初始提交
無檔案要提交(建立/拷貝檔案並使用"git add" 建立跟蹤)
[email protected]:~/gitfolder$

  
5 在倉庫裡面建立一個檔案,並將這個檔案新增到倉庫中(注意也可以使用git add .將之新增到版本倉庫中)
[email protected]:~/gitfolder$ touch readme.txt
[email protected]:~/gitfolder$ git status
位於分支 master
初始提交
未跟蹤的檔案:
  (使用 "git add <file>..." 以包含要提交的內容)
    readme.txt
提交為空,但是存在尚未跟蹤的檔案(使用
 "git add" 建立跟蹤)
[email protected]:~/gitfolder$ls
readme.txt

  
6 將新建的檔案新增到跟蹤,命令如下:
[email protected]:~/gitfolder$ git status
位於分支 master
初始提交
要提交的變更:
  (使用 "git rm --cached <file>..." 撤出暫存區)
 新檔案:readme.txt
[email protected]:~/gitfolder$

  
7readme.txt提交到git版本倉庫,命令如下:
[email protected]:~/gitfolder$git commit -m 'commit readme.txt'
[master(根提交) ad32b61]commit readme.txt
 1  file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 readme.txt
[email protected]:~/gitfolder$git status
位於分支 master
無檔案要提交,乾淨的工作區
[email protected]:~/gitfolder$

  
8檢視當前分支資訊,命令如下:
[email protected]:~/gitfolder$git branch
*master
 
或者使用
git branch -a

  
9檢視日誌資訊,命令如下:
[email protected]:~/gitfolder$]git log
commit ad32b612b632ab62e6fe46630f3c6b03a1ff1ce3
Author: tuzuoquan <[email protected]>
Date:Sat Nov 22 23:31:12 2014 +0800
    commit readme.txt
[email protected]:~/gitfolder$]git status
位於分支 master
無檔案要提交,乾淨的工作區
[email protected]:~/gitfolder$

  
10編輯readme.txt中的內容,並將之新增跟蹤,並將之提交到版本倉庫中去
readme.txt中的內容如下:
23:39 master readme.txt
   
檢視git版本的狀態,readme.txt新增到git.整個過程的命令如下:
[email protected]:~/gitfolder$git status
位於分支 master
尚未暫存以備提交的變更:
  (使用 "git add <file>..." 更新要提交的內容)
  (使用 "git checkout -- <file>..." 丟棄工作區的改動)
 修改:readme.txt
修改尚未加入提交(使用 "git add" /"git commit -a"
[email protected]:~/gitfolder$git add readme.txt 
[email protected]:~/gitfolder$git status 
位於分支 master
要提交的變更:
  (使用 "git reset HEAD <file>..." 撤出暫存區)
 修改:readme.txt
[email protected]:~/gitfolder$git add readme.txt
[email protected]:~/gitfolder$git commit -m 'commited after modify'
[master b5c97f9] commited after modify
 1 file changed, 2 insertions(+)

  
11建立一個develop分支,檢視所有的分支,命令如下:
[email protected]:~/gitfolder$git branch develop
[email protected]:~/gitfolder$git branch -a
  develop
*master
[email protected]:~/gitfolder$

  
12檢視git的日誌資訊
[email protected]:~/gitfolder$git log
commit b5c97f9ad74458b1ec6a7fc38684305e45fff4de
Author:tuzuoquan <[email protected]>
Date:Sat Nov 22 23:49:49 2014 +0800
    commited after modify
commit ad32b612b632ab62e6fe46630f3c6b03a1ff1ce3
Author: tuzuoquan <[email protected]>
Date: Sat Nov 22 23:31:12 2014 +0800
    commit readme.txt
[email protected]:~/gitfolder$

  
13切換到develop的分支,命令如下:
[email protected]:~/gitfolder$git checkout develop
切換到分支 'develop'
[email protected]:~/gitfolder$ls
readme.txt
[email protected]:~/gitfolder$git branch
*develop
  master
[email protected]:~/gitfolder$ 

  
14建立2.txt,並將檔案新增到對應的分支的版本倉庫中.
[email protected]:~/gitfolder$touch 2.txt
[email protected]:~/gitfolder$ls
2.txt readme.txt
[email protected]:~/gitfolder$git status
位於分支 develop
未跟蹤的檔案:
  (使用 "git add <file>..." 以包含要提交的內容)
 2.txt
提交為空,但是存在尚未跟蹤的檔案(使用"git add" 建立跟蹤)
[email protected]:~/gitfolder$vi 2.txt

  

14 切換到develop分支

[email protected]:~/gitfolder$ git checkout develop

已經位於 'develop'

檢視切換後的分支

[email protected]:~/gitfolder$ git branch -a

* develop

  master

[email protected]:~/gitfolder$ ls

2.txt  readme.txt

15 轉換到master分支然後建立一個

[email protected]:~/gitfolder$ git checkout master

切換到分支 'master'

建立一個分支develop2

[email protected]:~/gitfolder$ git branch develop2

[email protected]:~/gitfolder$ git checkout develop2

切換到分支 'develop2'

[email protected]:~/gitfolder$ ls

2.txt  readme.txt

16 切換分支資訊,並檢視所在分支資訊

[email protected]:~/gitfolder$ git checkout develop

切換到分支 'develop'

[email protected]:~/gitfolder$ git branch

* develop

  develop2

  master

[email protected]:~/gitfolder$

[email protected]:~/gitfolder$ git branch

* develop

  develop2

  master

[email protected]:~/gitfolder$ ls

2.txt  readme.txt

對develop分支中的readme.txt檔案中的內容進行修改

[email protected]:~/gitfolder$ vi readme.txt

[email protected]:~/gitfolder$ git status

位於分支 develop

尚未暫存以備提交的變更:

  (使用 "git add <file>..." 更新要提交的內容)

  (使用 "git checkout -- <file>..." 丟棄工作區的改動)

       修改:         readme.txt

未跟蹤的檔案:

  (使用 "git add <file>..." 以包含要提交的內容)

       .2.txt.swp

       2.txt

修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

[email protected]:~/gitfolder$

//將修改新增到分支

[email protected]:~/gitfolder$ git add .

[email protected]:~/gitfolder$ git commit -m 'xiugai'

[develop 722fbeb] xiugai

 3 files changed, 2 insertions(+)

 create mode 100644 .2.txt.swp

 create mode 100644 2.txt

17 切換分支到branch上,同時也修改develop分支中的檔案readme.txt檔案

[email protected]:~/gitfolder$ git branch

* develop

  develop2

  master

[email protected]:~/gitfolder$ git checkout develop2

切換到分支 'develop2'

[email protected]:~/gitfolder$ ls

readme.txt

[email protected]:~/gitfolder$ vi readme.txt

[email protected]:~/gitfolder$ git status

位於分支 develop2

尚未暫存以備提交的變更:

  (使用 "git add <file>..." 更新要提交的內容)

  (使用 "git checkout -- <file>..." 丟棄工作區的改動)

       修改:         readme.txt

修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

[email protected]:~/gitfolder$ git commit -m 'develop2 commited after modified'

位於分支 develop2

尚未暫存以備提交的變更:

修改:         readme.txt

修改尚未加入提交

[email protected]:~/gitfolder$ git add .

[email protected]:~/gitfolder$ git commit -m 'develop2 commited after modified'

[develop2 8e8dc62] develop2 commited after modified

 1 file changed, 1 insertion(+)

[email protected]:~/gitfolder$

18 先將develop合併到master,並解決合併衝突問題

[email protected]:~/gitfolder$ git merge develop

自動合併 readme.txt

衝突(內容):合併衝突於 readme.txt

自動合併失敗,修正衝突然後提交修正的結果。

[email protected]:~/gitfolder$

衝突的內容如下:

23:39 master readme.txt

<<<<<<< HEAD

11 : 00

=======

08:47 修改

>>>>>>> develop

為了解決合併時出現的衝突,需要修改readme.txt中的內容,修改後的內容如下:

23:39 master readme.txt

08:47 修改

19 檢視狀態,並將修改正確後的檔案提交到倉庫中

[email protected]:~/gitfolder$ git status

位於分支 develop2

您有尚未合併的路徑。

   (解決衝突並執行 "git commit")

要提交的變更:

新檔案:       .2.txt.swp

新檔案:       2.txt

未合併的路徑:

   (使用 "git add <file>..." 標記解決方案)

雙方修改:     readme.txt

20 將修改後的所有內容新增到倉庫中

[email protected]:~/gitfolder$ git add .

[email protected]:~/gitfolder$ git status

位於分支 develop2

所有衝突已解決但您仍處於合併中。

   (使用 "git commit" 結束合併)

    要提交的變更

新檔案:       .2.txt.swp

新檔案:       2.txt

修改:         readme.txt

[email protected]:~/gitfolder$ git commit -m 'commit all'

[develop2 749fb3c] commit all

[email protected]:~/gitfolder$

檢視修改後的內容

[email protected]:~/gitfolder$ cat readme.txt

23:39 master readme.txt

08:47 修改

[email protected]:~/gitfolder$


  
            
 
 

給我老師的人工智慧教程打call!http://blog.csdn.net/jiangjunshow

這裡寫圖片描述