$ work % cd workspace $ workspace % mkdir WebService //建立文件夾 $ workspace % git init //初始化 Initialized empty Git repository in /Users/jack/work/workspace/.git/ $ workspace %
$ workspace % cd .git $ .git % ls HEAD branches config description hooks info objects refs $ .git % ls -l total 24 -rw-r--r-- 1 jack staff 23 Sep 25 22:16 HEAD drwxr-xr-x 2 jack staff 64 Sep 25 22:16 branches -rw-r--r-- 1 jack staff 137 Sep 25 22:16 config -rw-r--r-- 1 jack staff 73 Sep 25 22:16 description drwxr-xr-x 13 jack staff 416 Sep 25 22:16 hooks drwxr-xr-x 3 jack staff 96 Sep 25 22:16 info drwxr-xr-x 4 jack staff 128 Sep 25 22:16 objects drwxr-xr-x 4 jack staff 128 Sep 25 22:16 refs $ .git %
注意:.git目錄中的文件不要刪除也不要修改,不然git不能正常工做。git
$ WebService % git config user.name njzy $ WebService % git config user.email njzy@2020.com $ WebService %2.系統用戶級別
$ WebService % git config --global user.name njzy_global $ WebService % git config --global user.email njzy_global@2020.com $ WebService %
$ WebService % cat .git/config //查看當前項目的簽名信息 [core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true ignorecase = true precomposeunicode = true [user] name = njzy //被設置的項目用戶名 email = njzy@2020.com //被設置的項目郵件地址 $ WebService %2.系統用戶級別
$ ~ % cd ~ //切換到當前用戶根目錄 $ ~ % pwd //查看當前位置 /Users/jack $ ~ % cat .gitconfig //查看全局簽名信息 [user] name = njzy_global //被設置的全局用戶名 email = njzy_global@2020.com //被設置的全局郵件地址 $ ~ %
usage: git add [<options>] [--] <pathspec>... -n, --dry-run dry run -v, --verbose be verbose -i, --interactive interactive picking -p, --patch select hunks interactively -e, --edit edit current diff and apply -f, --force allow adding otherwise ignored files -u, --update update tracked files //更新追蹤的文件 --renormalize renormalize EOL of tracked files (implies -u) -N, --intent-to-add record only the fact that the path will be added later -A, --all add changes from all tracked and untracked files //添加全部被追蹤文件的更新,和沒有被追蹤的文件 --ignore-removal ignore paths removed in the working tree (same as --no-all) //忽略工做區被刪除的文件 --refresh don't add, only refresh the index --ignore-errors just skip files which cannot be added because of errors //忽略因爲文件的錯誤不能被追蹤 --ignore-missing check if - even missing - files are ignored in dry run --chmod (+|-)x override the executable bit of the listed files
$ WebService % git status On branch master No commits yet //本地倉庫沒有可提交的東西 nothing to commit (create/copy files and use "git add" to track) //暫存區沒有能夠提交的東西 $ WebService %2.建立文件testGIt.txt文件
$ WebService % vim testGit.txt $ WebService % cat testGit.txt //查看文件內容 hello ! this is my first git test file ! $ WebService %3.查看文件建立完後git狀態
$ WebService % git status On branch master No commits yet //本地倉庫沒有樂意提交的東西。 Untracked files: //沒有追加跟蹤的文件 (use "git add <file>..." to include in what will be committed) //使用git add <file> 命令能夠追加文件到暫存區 testGit.txt //剛纔新建立的文件,此時文件名字體爲紅色 nothing added to commit but untracked files present (use "git add" to track) //使用git add命令 $ WebService %4.將文件添加到暫存區並查看狀態
$ WebService % git add testGit.txt $ WebService % git status On branch master No commits yet Changes to be committed: (use "git rm --cached <file>..." to unstage) //已經把文件放到暫存區,若是想清除暫存區,可使用git rm --cached 文件名來擦除暫存區 testGit.txt new file: testGit.txt //此時文件爲綠色 $ WebService %
usage: git commit [<options>] [--] <pathspec>... -q, --quiet suppress summary after successful commit -v, --verbose show diff in commit message template Commit message options -F, --file <file> read message from file --author <author> override author for commit --date <date> override date for commit -m, --message <message> commit message -c, --reedit-message <commit> reuse and edit message from specified commit -C, --reuse-message <commit> reuse message from specified commit --fixup <commit> use autosquash formatted message to fixup specified commit --squash <commit> use autosquash formatted message to squash specified commit --reset-author the commit is authored by me now (used with -C/-c/--amend) -s, --signoff add Signed-off-by: -t, --template <file> use specified template file -e, --edit force edit of commit --cleanup <mode> how to strip spaces and #comments from message --status include status in commit message template -S, --gpg-sign[=<key-id>] GPG sign commit Commit contents options -a, --all commit all changed files -i, --include add specified files to index for commit --interactive interactively add files -p, --patch interactively add changes -o, --only commit only specified files -n, --no-verify bypass pre-commit and commit-msg hooks --dry-run show what would be committed --short show status concisely --branch show branch information --ahead-behind compute full ahead/behind values --porcelain machine-readable output --long show status in long format (default) -z, --null terminate entries with NUL --amend amend previous commit --no-post-rewrite bypass post-rewrite hook -u, --untracked-files[=<mode>] show untracked files, optional modes: all, normal, no. (Default: all)
$ WebService % git commit -m "first commit:new file testGit.txt" testGit.txt [master (root-commit) c970a17] first commit:new file testGit.txt //first commit:new file testGit.txt 是提交時候的註釋信息 1 file changed, 2 insertions(+) //改變了一個文件,追加了兩行信息。 create mode 100644 testGit.txt $ WebService % git status On branch master nothing to commit, working tree clean //暫存區沒有能夠提交的東西 $ WebService %
$ WebService % git rm --cached testGit.txt rm 'testGit.txt' $ WebService % git status On branch master No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) testGit.txt //沒有被追蹤的文件 nothing added to commit but untracked files present (use "git add" to track) $ WebService %
$ WebService % git log //第二次被提交的信息 commit 148942fd3c0ff3e01e09bf98d883f97a3b0a9c86 (HEAD -> master) //提交版本的hash值 Author: njzy <njzy@2020.com> //提交用戶信息 Date: Sat Sep 26 15:53:52 2020 +0900 //提交日期 this is my second commit, modify testGit.txt //提交時註釋 //第一次被提交的信息 commit c970a176de13abc4d436e4a08df329046ef193e7 Author: njzy <njzy@2020.com> Date: Sat Sep 26 12:30:20 2020 +0900 first commit:new file testGit.txt $ WebService %
$ WebService % git log --pretty=oneline 148942fd3c0ff3e01e09bf98d883f97a3b0a9c86 (HEAD -> master) this is my second commit, modify testGit.txt c970a176de13abc4d436e4a08df329046ef193e7 first commit:new file testGit.txt $ WebService %
$ WebService % git log --oneline 148942f (HEAD -> master) this is my second commit, modify testGit.txt c970a17 first commit:new file testGit.txt $ WebService %
$ WebService % git reflog 148942f (HEAD -> master) HEAD@{0}: commit: this is my second commit, modify testGit.txt //148942f:簡短的hash地址 //HEAD@{0}:指針0的位置 c970a17 HEAD@{1}: commit (initial): first commit:new file testGit.txt //HEAD@{1} 指針1的位置 $ WebService %
$ WebService % git reflog //首先查看各類版本信息 d3c9608 (HEAD -> master) HEAD@{0}: commit: this is my fifth updata,updata testGit.txt 364024e HEAD@{1}: commit: this is my fourth commit,updata testGit.txt 9dba7c5 HEAD@{2}: commit: this is my third commit,updata testGit.txt 148942f HEAD@{3}: commit: this is my second commit, modify testGit.txt c970a17 HEAD@{4}: commit (initial): first commit:new file testGit.txt $ WebService % cat testGit.txt //查看當前版本的文件內容 hello ! this is my first git test file ! this is added this is my third updata! this is my four updata! this is my fifth updata! $ WebService % git reset --hard 9dba7c5 //而後根據查看的版本地址信息,指定到要恢復到的版本。 HEAD is now at 9dba7c5 this is my third commit,updata testGit.txt $ WebService % cat testGit.txt //而後查看回退後的當前版本文件內容 hello ! this is my first git test file ! this is added this is my third updata! $ WebService % git reflog //而後咱們再來看一下log信息 9dba7c5 (HEAD -> master) HEAD@{0}: reset: moving to 9dba7c5 d3c9608 HEAD@{1}: commit: this is my fifth updata,updata testGit.txt 364024e HEAD@{2}: commit: this is my fourth commit,updata testGit.txt 9dba7c5 (HEAD -> master) HEAD@{3}: commit: this is my third commit,updata testGit.txt 148942f HEAD@{4}: commit: this is my second commit, modify testGit.txt c970a17 HEAD@{5}: commit (initial): first commit:new file testGit.txt $ WebService %
$ WebService % git reset --hard HEAD^ HEAD is now at 9dba7c5 this is my third commit,updata testGit.txt $ WebService % cat testGit.txt hello ! this is my first git test file ! this is added this is my third updata! $ WebService %倒退兩個版本
$ WebService % git reset --hard HEAD^^ HEAD is now at c970a17 first commit:new file testGit.txt $ WebService % cat testGit.txt hello ! this is my first git test file ! $ WebService %
$ WebService % git reset --hard HEAD~2 HEAD is now at 9dba7c5 this is my third commit,updata testGit.txt $ WebService % cat testGit.txt hello ! this is my first git test file ! this is added this is my third updata! $ WebService %
$ WebService % cat testGit.txt //退回版本以前查看文件內容 hello ! this is my first git test file ! this is added this is my third updata! $ WebService % git reset --soft 148942f //退回版本操做 $ WebService % cat testGit.txt //退回版本信息後查看文件內容 hello ! this is my first git test file ! this is added this is my third updata! $ WebService % git status //查看狀態 On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: testGit.txt //查看完後顯示爲綠色字體,表示被更改了。爲哈如此呢? //是因爲原來本地倉庫,暫存區,工做區的指針是相同的。而通過soft操做後,本地倉庫的指針發生變化,致使暫存區的指針相對的產生了變化。因此顯示是發生了變化。 $ WebService %
$ WebService % cat testGit.txt //跳轉到其餘版本以前文件內容 hello ! this is my first git test file ! this is added this is my third updata! $ WebService % git reset --mixed d3c9608 //指定到指定版本 Unstaged changes after reset: M testGit.txt $ WebService % git reflog //指定版本後的日誌 d3c9608 (HEAD -> master) HEAD@{0}: reset: moving to d3c9608 148942f HEAD@{1}: reset: moving to 148942f 9dba7c5 HEAD@{2}: reset: moving to HEAD~2 d3c9608 (HEAD -> master) HEAD@{3}: reset: moving to d3c9608 c970a17 HEAD@{4}: reset: moving to HEAD^^ 9dba7c5 HEAD@{5}: reset: moving to HEAD^ 364024e HEAD@{6}: reset: moving to 364024e 9dba7c5 HEAD@{7}: reset: moving to 9dba7c5 d3c9608 (HEAD -> master) HEAD@{8}: commit: this is my fifth updata,updata testGit.txt 364024e HEAD@{9}: commit: this is my fourth commit,updata testGit.txt 9dba7c5 HEAD@{10}: commit: this is my third commit,updata testGit.txt 148942f HEAD@{11}: commit: this is my second commit, modify testGit.txt c970a17 HEAD@{12}: commit (initial): first commit:new file testGit.txt $ WebService % cat testGit.txt //查看切換版本後的文件內容 hello ! this is my first git test file ! this is added this is my third updata! $ WebService % git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: testGit.txt //此時文件名是紅色 no changes added to commit (use "git add" and/or "git commit -a") $ WebService %
$ WebService % vim test2.txt //1.建立一個新的測試文件 $ WebService % git add test2.txt //2.添加到暫存區 $ WebService % git commit -m "add new test2.txt" test2.txt //3.提交到本地倉庫 [master 8a4e57d] add new test2.txt 1 file changed, 3 insertions(+) create mode 100644 test2.txt $ WebService % ls -l //查看當前文件夾文件 total 16 -rw-r--r-- 1 jack staff 27 Sep 27 07:11 test2.txt -rw-r--r-- 1 jack staff 134 Sep 26 22:33 testGit.txt $ WebService % git status //查看git狀態 On branch master nothing to commit, working tree clean $ WebService % $ WebService % $ WebService % $ WebService % rm test2.txt //4.本地物理刪除文件 $ WebService % ls -l //5.刪除後確認 total 8 -rw-r--r-- 1 jack staff 134 Sep 26 22:33 testGit.txt $ WebService % git status //6.查看刪除後 On branch master Changes not staged for commit: (use "git add/rm <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) deleted: test2.txt //紅色字體,表示這個操做沒有被添加到暫存區 no changes added to commit (use "git add" and/or "git commit -a") $ WebService % git add test2.txt //7.將刪除後的狀態添加到暫存區 $ WebService % git status //查看添加後的git狀態 On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) deleted: test2.txt //文字爲綠色,表示暫存區已被更新。 $ WebService % git commit -m "delete file test2.txt" test2.txt //8.把暫存區內容提交到本地倉庫 [master f8373c4] delete file test2.txt 1 file changed, 3 deletions(-) delete mode 100644 test2.txt $ WebService % git status //查看git狀態 On branch master nothing to commit, working tree clean $ WebService % ls testGit.txt $ WebService % git reflog //9.查看日誌信息 f8373c4 (HEAD -> master) HEAD@{0}: commit: delete file test2.txt //10/1文件被刪除的歷史記錄 8a4e57d HEAD@{1}: commit: add new test2.txt d3c9608 HEAD@{2}: reset: moving to d3c9608 d3c9608 HEAD@{3}: reset: moving to d3c9608 148942f HEAD@{4}: reset: moving to 148942f 9dba7c5 HEAD@{5}: reset: moving to HEAD~2 d3c9608 HEAD@{6}: reset: moving to d3c9608 c970a17 HEAD@{7}: reset: moving to HEAD^^ 9dba7c5 HEAD@{8}: reset: moving to HEAD^ 364024e HEAD@{9}: reset: moving to 364024e 9dba7c5 HEAD@{10}: reset: moving to 9dba7c5 d3c9608 HEAD@{11}: commit: this is my fifth updata,updata testGit.txt 364024e HEAD@{12}: commit: this is my fourth commit,updata testGit.txt 9dba7c5 HEAD@{13}: commit: this is my third commit,updata testGit.txt 148942f HEAD@{14}: commit: this is my second commit, modify testGit.txt c970a17 HEAD@{15}: commit (initial): first commit:new file testGit.txt $ WebService % git reset --hard 8a4e57d //2.恢復到刪除以前的版本 HEAD is now at 8a4e57d add new test2.txt $ WebService % ls -l//3.查看本地文件是否恢復? total 16 -rw-r--r-- 1 jack staff 27 Sep 27 07:25 test2.txt//文件又被恢復回來了 -rw-r--r-- 1 jack staff 134 Sep 26 22:33 testGit.txt $ WebService %
aaaaaaaa bbbbbbbb cccccccc修改後的工做區test2.txt
aaaaaaaa bbbbbbbb cccccccc@@@@@@比較後結果
$ WebService % git diff test2.txt diff --git a/test2.txt b/test2.txt index 092b923..0c08686 100644 --- a/test2.txt +++ b/test2.txt @@ -1,3 +1,3 @@ aaaaaaaa bbbbbbbb -cccccccc //-表明刪除 +cccccccc@@@@@@ //+表明追加。git是以行尾單位來管理版本的,因此cccccccc表示爲刪除,cccccccc@@@@@@表示爲追加。 $ WebService %提交到暫存區後再比較
$ WebService % git add test2.txt $ WebService % git diff test2.txt $ WebService %
$ WebService % git reset --hard HEAD //先把三個區同步一下,恢復到同一狀態 HEAD is now at 8a4e57d add new test2.txt $ WebService % git status On branch master nothing to commit, working tree clean $ WebService % cat test2.txt aaaaaaaa bbbbbbbb cccccccc $ WebService % vim test2.txt //對工做區修改 $ WebService % git diff HEAD test2.txt//修改後進行比較 diff --git a/test2.txt b/test2.txt index 092b923..0c08686 100644 --- a/test2.txt +++ b/test2.txt @@ -1,3 +1,3 @@ aaaaaaaa bbbbbbbb -cccccccc +cccccccc@@@@@@ $ WebService %和本地倉庫的上一個版本進行比較
$ WebService % git diff HEAD^ test2.txt diff --git a/test2.txt b/test2.txt new file mode 100644 index 0000000..0c08686 --- /dev/null +++ b/test2.txt @@ -0,0 +1,3 @@ +aaaaaaaa +bbbbbbbb +cccccccc@@@@@@ $ WebService %
在版本控制過程當中,使用多條線同時推動多個任務。
$ WebService % git branch hot_fix
$ WebService % git branch -v hot_fix 8a4e57d add new test2.txt * master 8a4e57d add new test2.txt //*所在的位值就是咱們如今因此在的分支 $ WebService %
$ WebService % git checkout hot_fix Switched to branch 'hot_fix' $ WebService % git branch -v * hot_fix 8a4e57d add new test2.txt //如今已經切換到hot_fix分支 master 8a4e57d add new test2.txt $ WebService %
$ WebService % git branch -v //查看當前分支 * hot_fix a360edf hox_fix one add master 8a4e57d add new test2.txt $ WebService % git checkout master //切換到內容要合併到的分支 Switched to branch 'master' $ WebService % git branch -v //再次確認切換後的分支 hot_fix a360edf hox_fix one add * master 8a4e57d add new test2.txt $ WebService % git merge hot_fix //進行分支合併 Updating 8a4e57d..a360edf Fast-forward test2.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) $ WebService % cat test2.txt//查看合併後的內容 aaaaaaaa bbbbbbbb cccccccc edit by hox_fix//次內容是hot_fix分支內容,證實已經合併成功。 $ WebService % git branch -v hot_fix a360edf hox_fix one add //當兩個分支內容同樣的時候,此時兩個分支的hash值是同樣的。 * master a360edf hox_fix one add //當兩個分支內容同樣的時候,此時兩個分支的hash值是同樣的。 $ WebService %
$ WebService % vim test2.txt //修改mster分支的test2文件 $ WebService % git add test2.txt //把修改後的文件添加到暫存區 $ WebService % git commit test2.txt //把暫存區文件提交到本地倉庫 [master 4a902f1] updata master 1 file changed, 1 insertion(+) $ WebService % git branch -v //查看當前分支 hot_fix a360edf hox_fix one add * master 4a902f1 updata master $ WebService % $ WebService % git checkout hot_fix //切換到hot_fix分支 Switched to branch 'hot_fix' $ WebService % git branch -v //查看分支 * hot_fix a360edf hox_fix one add master 4a902f1 updata master $ WebService % vim test2.txt //編輯test2.txt $ WebService % git add test2.txt //修改後的文件添加到暫存區 $ WebService % git commit -m "updata hox_fix" test2.txt //提交文件到本地倉庫 [hot_fix ee3ae4c] updata hox_fix 1 file changed, 1 insertion(+) $ WebService % $ WebService % git merge master //合併分支 Auto-merging test2.txt CONFLICT (content): Merge conflict in test2.txt Automatic merge failed; fix conflicts and then commit the result. //自動合併分支失敗,接下來須要手動修改文件後在進行提交來解決衝突 $ WebService % ls -l total 16 -rw-r--r-- 1 jack staff 126 Sep 27 11:02 test2.txt -rw-r--r-- 1 jack staff 134 Sep 26 22:33 testGit.txt $ WebService % vim test2.txt //打開文件進行手動合併文件內容 $ WebService % git status //查看git狀態 On branch hot_fix //在hot_fix分支上 You have unmerged paths.//沒有合併的路徑 (fix conflicts and run "git commit") //修理衝突並執行 (use "git merge --abort" to abort the merge) //終止合併 Unmerged paths: (use "git add <file>..." to mark resolution) //使用git add <file> 命令去標記爲解決 both modified: test2.txt no changes added to commit (use "git add" and/or "git commit -a") $ WebService % git add test2.txt //解決衝突後的文件添加到暫存區 $ WebService % git status On branch hot_fix All conflicts fixed but you are still merging.//全部的衝突已經解決了,可是你仍然處於「合併中」狀態。 (use "git commit" to conclude merge) //使用git commit 命令去變換」合併中「的狀態 Changes to be committed: modified: test2.txt $ WebService % git commit -m "resolve conflict" test2.txt fatal: cannot do a partial commit during a merge. //注意:在這中特殊場合下的commit不能再後面使用文件名 $ WebService % git commit -m "resolve conflict" //去掉文件名再次執行提交。 [hot_fix 0d62477] resolve conflict //衝突解決了。 $ WebService % git status //查看git狀態 On branch hot_fix nothing to commit, working tree clean $ WebService % vim test2.txt //確認合併後的內容 $ WebService %上面執行完merge命令後,test2.txt文件的內容,
aaaaaaaa bbbbbbbb cccccccc edit by hox_fix <<<<<<< HEAD //指針版本內容 eeeeeeee add by hox_fix ======= dddddddd add by master >>>>>>> master //master版本內容上面修改後的文件內容
aaaaaaaa bbbbbbbb cccccccc edit by hox_fix dddddddd add by master eeeeeeee add by hox_fix
$ WebService % git remote add origin https://github.com/jack2019/WebService.git $ WebService %
$ WebService % git remote -v origin https://github.com/jack2019/WebService.git (fetch) origin https://github.com/jack2019/WebService.git (push) $ WebService %
$ WebService % git push origin hot_fix Enumerating objects: 30, done. Counting objects: 100% (30/30), done. Delta compression using up to 16 threads Compressing objects: 100% (22/22), done. Writing objects: 100% (30/30), 2.52 KiB | 1.26 MiB/s, done. Total 30 (delta 4), reused 0 (delta 0) remote: Resolving deltas: 100% (4/4), done. remote: remote: Create a pull request for 'hot_fix' on GitHub by visiting: remote: https://github.com/jack2019/WebService/pull/new/hot_fix remote: To https://github.com/jack2019/WebService.git * [new branch] hot_fix -> hot_fix $ WebService %
$ WebService % git push origin master //首次推送 To https://github.com/jack2019/WebService.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://github.com/jack2019/WebService.git' //推送失敗 hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. $ WebService % git push origin master -f //進行強行推送 Total 0 (delta 0), reused 0 (delta 0) To https://github.com/jack2019/WebService.git + 6cfbddc...4a902f1 master -> master (forced update) //強行推送成功,能夠去github倉庫查看是否已經有上傳的內容。 $ WebService %
➜ IdeaProjects git clone https://github.com/jack2019/gitLearnning.git //克隆遠程倉庫庫 Cloning into 'gitLearnning'... remote: Enumerating objects: 52, done. remote: Counting objects: 100% (52/52), done. remote: Compressing objects: 100% (34/34), done. remote: Total 52 (delta 10), reused 51 (delta 10), pack-reused 0 Unpacking objects: 100% (52/52), done. //克隆成功 ➜ IdeaProjects cd gitLearnning //進入下載的文件夾 ➜ gitLearnning git:(master) ls -al //查看下載的文件 total 16 drwxr-xr-x 5 jack staff 160 Oct 6 21:34 . drwxr-xr-x@ 21 jack staff 672 Oct 6 21:34 .. drwxr-xr-x 13 jack staff 416 Oct 6 21:34 .git -rw-r--r-- 1 jack staff 219 Oct 6 21:34 test2.txt -rw-r--r-- 1 jack staff 134 Oct 6 21:34 testGit.txt ➜ gitLearnning git:(master) git status //查看git狀態 On branch master Your branch is up to date with 'origin/master'. //被下載到了origin/master下 nothing to commit, working tree clean ➜ gitLearnning git:(master)
$ git fetch origin master //抓取內容 remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/jack2019/WebService * branch master -> FETCH_HEAD f1a3142..da6a4ee master -> origin/master Window-PC MINGW64 /e/workspace/web/webservice (master) $ ls -l total 2 -rw-r--r-- 1 laofan 197121 100 九月 28 21:30 test2.txt -rw-r--r-- 1 laofan 197121 144 九月 28 21:30 testGit.txt Window-PC MINGW64 /e/workspace/web/webservice (master) $ cat test2.txt aaaaaaaa bbbbbbbb cccccccc edit by hox_fix dddddddd add by master mmmmmmm push after updata! Window-PC MINGW64 /e/workspace/web/webservice (master) $ git checkout origin/master //fetch下來的內容放在origin/master下,切換分支到origin、master下。 Note: checking out 'origin/master'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b <new-branch-name> HEAD is now at da6a4ee... mac commit ,window fetch Window-PC MINGW64 /e/workspace/web/webservice ((da6a4ee...)) $ git branch -v //查看當前分支 * (HEAD detached at origin/master) da6a4ee mac commit ,window fetch master f1a3142 [behind 1] push after updata test2.txt //當前所處的分支是origin/master下 Window-PC MINGW64 /e/workspace/web/webservice ((da6a4ee...)) $ cat test2.txt //查看當前分支下的文件內容 aaaaaaaa bbbbbbbb cccccccc edit by hox_fix dddddddd add by master mmmmmmm push after updata nnnnnnn macbook add! //當前分支新追加的內容 Window-PC MINGW64 /e/workspace/web/webservice ((da6a4ee...)) $ git checkout master //切換分支到master Previous HEAD position was da6a4ee... mac commit ,window fetch Switched to branch 'master' Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded. (use "git pull" to update your local branch) Window-PC MINGW64 /e/workspace/web/webservice (master) $ git branch -v //查看當前分支 * master f1a3142 [behind 1] push after updata test2.txt Window-PC MINGW64 /e/workspace/web/webservice (master) $ cat test2.txt //查看當前分支內容 aaaaaaaa bbbbbbbb cccccccc edit by hox_fix dddddddd add by master mmmmmmm push after updata! Window-PC MINGW64 /e/workspace/web/webservice (master) $ git merge origin/master //把origin/master分支內容合併到master Updating f1a3142..da6a4ee Fast-forward test2.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) Window-PC MINGW64 /e/workspace/web/webservice (master) $ cat test2.txt //查看合併後的master分支文件內容 aaaaaaaa bbbbbbbb cccccccc edit by hox_fix dddddddd add by master mmmmmmm push after updata nnnnnnn macbook add! //origin/master追加的內容 Window-PC MINGW64 /e/workspace/web/webservice (master)
$ git pull origin master remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/jack2019/WebService * branch master -> FETCH_HEAD da6a4ee..494ed55 master -> origin/master Updating da6a4ee..494ed55 Fast-forward test2.txt | 1 + 1 file changed, 1 insertion(+) Window-PC MINGW64 /e/workspace/web/webservice (master) $ cat test2.txt aaaaaaaa bbbbbbbb cccccccc edit by hox_fix dddddddd add by master mmmmmmm push after updata nnnnnnn macbook add! jjjjjjj macbook add2! Window-PC MINGW64 /e/workspace/web/webservice (master) $