1git命令的使用,查看git仓库状态,添加文件到git跟踪,git提交,查看git分支,查看git仓库日志信息,切换git分支,解决git分支合并后出现冲突的问题
| toto@toto-K45VD:~$ mkdir gitfolder |
| toto@toto-K45VD:~$cd gitfolder/ toto@toto-K45VD:~/gitfolder$ls toto@toto-K45VD:~/gitfolder$git init 初始化空的 Git版本庫于 /home/toto/gitfolder/.git/ 注意:如果是第一次使用git,還要對git對進行如下配置 git config --global user.email "yourEmail@qq.com" git config --global user.name "tuzuoquan" |
| toto@toto-K45VD:~/gitfolder$ll 總用量 12 drwxrwxr-x 3 toto toto 4096 11月 22 23:12 ./ drwxr-xr-x 31 toto toto 4096 11月 22 23:09 ../ drwxrwxr-x 7 toto toto 4096 11月 22 23:12 .git/ |
| toto@toto-K45VD:~/gitfolder$ git status 位于分支 master 初始提交 無文件要提交(創建/拷貝文件并使用"git add" 建立跟蹤) toto@toto-K45VD:~/gitfolder$ |
| toto@toto-K45VD:~/gitfolder$ touch readme.txt toto@toto-K45VD:~/gitfolder$ git status 位于分支 master 初始提交 未跟蹤的文件: (使用 "git add <file>..." 以包含要提交的內容) readme.txt 提交為空,但是存在尚未跟蹤的文件(使用 "git add" 建立跟蹤) toto@toto-K45VD:~/gitfolder$ls readme.txt |
| toto@toto-K45VD:~/gitfolder$ git status 位于分支 master 初始提交 要提交的變更: (使用 "git rm --cached <file>..." 撤出暫存區) 新文件:readme.txt toto@toto-K45VD:~/gitfolder$ |
| toto@toto-K45VD:~/gitfolder$git commit -m 'commit readme.txt' [master(根提交) ad32b61] commit readme.txt 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 readme.txt toto@toto-K45VD:~/gitfolder$git status 位于分支 master 無文件要提交,干凈的工作區 toto@toto-K45VD:~/gitfolder$ |
| toto@toto-K45VD:~/gitfolder$git branch *master 或者使用 git branch -a |
| toto@toto-K45VD:~/gitfolder$]git log commit ad32b612b632ab62e6fe46630f3c6b03a1ff1ce3 Author: tuzuoquan <you@example.com> Date:Sat Nov 22 23:31:12 2014 +0800 commit readme.txt toto@toto-K45VD:~/gitfolder$]git status 位于分支 master 無文件要提交,干凈的工作區 toto@toto-K45VD:~/gitfolder$ |
| readme.txt中的內容如下: 23:39 master readme.txt 查看git版本的狀態,將readme.txt添加到git上.整個過程的命令如下: toto@toto-K45VD:~/gitfolder$git status 位于分支 master 尚未暫存以備提交的變更: (使用 "git add <file>..." 更新要提交的內容) (使用 "git checkout -- <file>..." 丟棄工作區的改動) 修改:readme.txt 修改尚未加入提交(使用 "git add" 和/或"git commit -a") toto@toto-K45VD:~/gitfolder$git add readme.txt toto@toto-K45VD:~/gitfolder$git status 位于分支 master 要提交的變更: (使用 "git reset HEAD <file>..." 撤出暫存區) 修改:readme.txt toto@toto-K45VD:~/gitfolder$git add readme.txt toto@toto-K45VD:~/gitfolder$git commit -m 'commited after modify' [master b5c97f9] commited after modify 1 file changed, 2 insertions(+) |
| toto@toto-K45VD:~/gitfolder$git branch develop toto@toto-K45VD:~/gitfolder$git branch -a develop *master toto@toto-K45VD:~/gitfolder$ |
| toto@toto-K45VD:~/gitfolder$git log commit b5c97f9ad74458b1ec6a7fc38684305e45fff4de Author:tuzuoquan <you@example.com> Date:Sat Nov 22 23:49:49 2014 +0800 commited after modify commit ad32b612b632ab62e6fe46630f3c6b03a1ff1ce3 Author: tuzuoquan <you@example.com> Date: Sat Nov 22 23:31:12 2014 +0800 commit readme.txt toto@toto-K45VD:~/gitfolder$ |
| toto@toto-K45VD:~/gitfolder$git checkout develop 切換到分支 'develop' toto@toto-K45VD:~/gitfolder$ls readme.txt toto@toto-K45VD:~/gitfolder$git branch *develop master toto@toto-K45VD:~/gitfolder$ |
| toto@toto-K45VD:~/gitfolder$touch 2.txt toto@toto-K45VD:~/gitfolder$ls 2.txt readme.txt toto@toto-K45VD:~/gitfolder$git status 位于分支 develop 未跟蹤的文件: (使用 "git add <file>..." 以包含要提交的內容) 2.txt 提交為空,但是存在尚未跟蹤的文件(使用"git add" 建立跟蹤) toto@toto-K45VD:~/gitfolder$vi 2.txt |
14 切換到develop分支
toto@toto-K45VD:~/gitfolder$ git checkout develop 已經位于'develop' 查看切換后的分支 toto@toto-K45VD:~/gitfolder$ git branch -a * develop ? master toto@toto-K45VD:~/gitfolder$ ls 2.txt? readme.txt |
15 轉換到master分支然后創建一個
toto@toto-K45VD:~/gitfolder$git checkout master 切換到分支 'master' 創建一個分支develop2 toto@toto-K45VD:~/gitfolder$ git branch develop2 toto@toto-K45VD:~/gitfolder$ git checkout develop2 切換到分支 'develop2' toto@toto-K45VD:~/gitfolder$ ls 2.txt? readme.txt |
16 切換分支信息,并查看所在分支信息
toto@toto-K45VD:~/gitfolder$git checkout develop 切換到分支 'develop' toto@toto-K45VD:~/gitfolder$ git branch * develop ? develop2 ? master toto@toto-K45VD:~/gitfolder$ toto@toto-K45VD:~/gitfolder$ git branch * develop ? develop2 ?master toto@toto-K45VD:~/gitfolder$ ls 2.txt? readme.txt 對develop分支中的readme.txt文件中的內容進行修改 toto@toto-K45VD:~/gitfolder$ vi readme.txt toto@toto-K45VD:~/gitfolder$ git status 位于分支 develop 尚未暫存以備提交的變更: ? (使用 "gitadd <file>..." 更新要提交的內容) ? (使用 "git checkout -- <file>..." 丟棄工作區的改動) ?????? 修改:???????? readme.txt 未跟蹤的文件: ? (使用 "git add <file>..." 以包含要提交的內容) ?????? .2.txt.swp ?????? 2.txt 修改尚未加入提交(使用 "git add" 和/或 "git commit -a") toto@toto-K45VD:~/gitfolder$ //將修改添加到分支 toto@toto-K45VD:~/gitfolder$git add . toto@toto-K45VD:~/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文件
toto@toto-K45VD:~/gitfolder$git branch * develop ? develop2 ? master toto@toto-K45VD:~/gitfolder$ git checkout develop2 切換到分支 'develop2' toto@toto-K45VD:~/gitfolder$ ls readme.txt toto@toto-K45VD:~/gitfolder$ vi readme.txt toto@toto-K45VD:~/gitfolder$git status 位于分支 develop2 尚未暫存以備提交的變更: ? (使用 "git add <file>..." 更新要提交的內容) ? (使用 "git checkout -- <file>..." 丟棄工作區的改動) ?????? 修改:???????? readme.txt 修改尚未加入提交(使用 "git add" 和/或 "git commit -a") toto@toto-K45VD:~/gitfolder$git commit -m 'develop2 commited after modified' 位于分支 develop2 尚未暫存以備提交的變更: 修改:???????? readme.txt 修改尚未加入提交 toto@toto-K45VD:~/gitfolder$ git add . toto@toto-K45VD:~/gitfolder$ git commit -m 'develop2 commited after modified' [develop28e8dc62] develop2 commited after modified ?1 file changed, 1 insertion(+) toto@toto-K45VD:~/gitfolder$ |
18 先將develop合并到master,并解決合并沖突問題
toto@toto-K45VD:~/gitfolder$git merge develop 自動合并 readme.txt 沖突(內容):合并沖突于 readme.txt 自動合并失敗,修正沖突然后提交修正的結果。 toto@toto-K45VD:~/gitfolder$ 沖突的內容如下: 23:39 master readme.txt <<<<<<< HEAD 11 : 00 ======= 08:47 修改 >>>>>>> develop 為了解決合并時出現的沖突,需要修改readme.txt中的內容,修改后的內容如下: 23:39master readme.txt 08:47 修改 |
19 查看狀態,并將修改正確后的文件提交到倉庫中
toto@toto-K45VD:~/gitfolder$ git status 位于分支 develop2 您有尚未合并的路徑。 ??(解決沖突并運行 "git commit") 要提交的變更: 新文件:?????? .2.txt.swp 新文件:?????? 2.txt 未合并的路徑: ?? (使用 "git add <file>..." 標記解決方案) 雙方修改:???? readme.txt |
20 將修改后的所有內容添加到倉庫中
toto@toto-K45VD:~/gitfolder$git add . toto@toto-K45VD:~/gitfolder$ git status 位于分支 develop2 所有沖突已解決但您仍處于合并中。 ? ?(使用 "git commit" 結束合并) ??? 要提交的變更 新文件:?????? .2.txt.swp 新文件:?????? 2.txt 修改:???????? readme.txt toto@toto-K45VD:~/gitfolder$git commit -m 'commit all' [develop2 749fb3c] commit all toto@toto-K45VD:~/gitfolder$ 查看修改后的內容 toto@toto-K45VD:~/gitfolder$ cat readme.txt 23:39 master readme.txt 08:47 修改 toto@toto-K45VD:~/gitfolder$ |
總結
以上是生活随笔為你收集整理的1git命令的使用,查看git仓库状态,添加文件到git跟踪,git提交,查看git分支,查看git仓库日志信息,切换git分支,解决git分支合并后出现冲突的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 排骨的做法大全家常?
- 下一篇: 广州早茶哪里好 推荐几家口碑不错的早茶店