====== git的操作学习 ====== cd /Users/guanxianghui/Documents/git git clone http://www.enjoyingshop.com/gxx/first-project.git ==== Cloning into 'first-project'... Username for 'http://www.enjoyingshop.com': gxx Password for 'http://gxx@www.enjoyingshop.com': ******** warning: You appear to have cloned an empty repository. Checking connectivity... done. ==== ls first-project cd first-project/ git status ==== On branch master Initial commit nothing to commit (create/copy files and use "git add" to track) ==== vim 1.txt git status ==== On branch master Initial commit Untracked files: (use "git add ..." to include in what will be committed) 1.txt nothing added to commit but untracked files present (use "git add" to track) ==== git commit -m 'commit 1.txt' ==== On branch master Initial commit Untracked files: 1.txt nothing added to commit but untracked files present ==== git add 1.txt git status ==== On branch master Initial commit Changes to be committed: (use "git rm --cached ..." to unstage) new file: 1.txt ==== git commit -m 'commit 1.txt' [master (root-commit) 4b25b16] commit 1.txt ==== 1 file changed, 1 insertion(+) create mode 100644 1.txt ==== git status ==== On branch master Your branch is based on 'origin/master', but the upstream is gone. (use "git branch --unset-upstream" to fixup) nothing to commit, working directory clean ==== git remote -v ==== origin http://www.enjoyingshop.com/gxx/first-project.git (fetch) origin http://www.enjoyingshop.com/gxx/first-project.git (push) ==== git branch -a ==== * master ==== git push origin master ==== Counting objects: 3, done. Writing objects: 100% (3/3), 214 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To http://www.enjoyingshop.com/gxx/first-project.git * [new branch] master -> master ==== git checkout dev ==== error: pathspec 'dev' did not match any file(s) known to git. ==== git checkout -b dev ==== Switched to a new branch 'dev' ==== git checkout -b uat ==== Switched to a new branch 'uat' ==== git branch -a ==== dev master * uat remotes/origin/master ==== git checkout dev ==== Switched to branch 'dev' ==== git branch -a ==== * dev master uat remotes/origin/master ==== vim 2.txt git add . git commit -m 'add 2.txt' ==== [dev d24315e] add 2.txt 1 file changed, 1 insertion(+) create mode 100644 2.txt ==== git checkout uat ==== Switched to branch 'uat' ==== ls ==== 1.txt ==== git merge dev #Fast-forward “快进模式”,直接把uat指向dev的当前提交,速度快 ==== Updating 4b25b16..d24315e Fast-forward 2.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 2.txt ==== git log ==== commit d24315ee87ca33533eaeff63a7d6eb35e3c78195 Author: guanxianghui Date: Sun Oct 16 22:03:05 2016 +0800 add 2.txt commit 4b25b167abb9a496ce1b49582ddc750781e2a220 Author: guanxianghui Date: Sun Oct 16 21:37:10 2016 +0800 commit 1.txt ==== git checkout dev ==== Switched to branch 'dev' ==== vim 1.txt git add . git commit -m 'update 1.txt add 1+1=2' ==== [dev 22ce71e] update 1.txt add 1+1=2 1 file changed, 2 insertions(+) ==== git checkout uat ==== Switched to branch 'uat' ==== git merge --no-ff -m "merge dev with no-ff" dev #表示禁用Fast forward,而且生成一个新的commit,这样,从分支历史上就可以看出分支信息 ==== Merge made by the 'recursive' strategy. 1.txt | 2 ++ 1 file changed, 2 insertions(+) ==== git log ==== commit b907c41069438f63108124cea92edb78f7e86b86 Merge: d24315e 22ce71e Author: guanxianghui Date: Sun Oct 16 22:11:04 2016 +0800 merge dev with no-ff commit 22ce71e58b9fa8863d05d2ff2fd35473c1d40824 Author: guanxianghui Date: Sun Oct 16 22:10:28 2016 +0800 update 1.txt add 1+1=2 commit d24315ee87ca33533eaeff63a7d6eb35e3c78195 Author: guanxianghui Date: Sun Oct 16 22:03:05 2016 +0800 add 2.txt commit 4b25b167abb9a496ce1b49582ddc750781e2a220 Author: guanxianghui Date: Sun Oct 16 21:37:10 2016 +0800 commit 1.txt ==== git checkout dev ==== Switched to branch 'dev' ==== vim 1.txt git add . git commit -m 'dev update 1.txt' ==== [dev 0b82b85] dev update 1.txt 1 file changed, 2 insertions(+) ==== git checkout uat ==== Switched to branch 'uat' ==== vim 1.txt ==== git add . git commit -m 'uat update 1.txt' ==== [uat a133e2b] uat update 1.txt 1 file changed, 2 insertions(+) ==== git merge --no-ff -m "merge dev with no-ff" dev #合并存在冲突 ==== Auto-merging 1.txt CONFLICT (content): Merge conflict in 1.txt Automatic merge failed; fix conflicts and then commit the result. ==== git status ==== On branch uat You have unmerged paths. (fix conflicts and run "git commit") Unmerged paths: (use "git add ..." to mark resolution) both modified: 1.txt no changes added to commit (use "git add" and/or "git commit -a") ==== vim 1.txt #手动解决冲突 ==== test add 1+1=2 <<<<<<< HEAD uat update here ======= dev update here >>>>>>> dev ==== 改成 ==== test add 1+1=2 uat update here not dev ==== git add . git commit -m '手动解决冲突' ==== [uat 81be372] 手动解决冲突 ==== git status ==== On branch uat nothing to commit, working directory clean ==== git push origin dev ==== Counting objects: 9, done. Delta compression using up to 4 threads. Compressing objects: 100% (6/6), done. Writing objects: 100% (9/9), 801 bytes | 0 bytes/s, done. Total 9 (delta 0), reused 0 (delta 0) To http://www.enjoyingshop.com/gxx/first-project.git * [new branch] dev -> dev ==== git push origin uat ==== Counting objects: 7, done. Delta compression using up to 4 threads. Compressing objects: 100% (5/5), done. Writing objects: 100% (7/7), 815 bytes | 0 bytes/s, done. Total 7 (delta 0), reused 0 (delta 0) To http://www.enjoyingshop.com/gxx/first-project.git * [new branch] uat -> uat ==== git push origin master ==== Everything up-to-date ==== git log --graph --pretty=oneline --abbrev-commit ==== * e936a3f 手动解决冲突 |\ | * 79f1681 dev update 1.txt * | 911d826 uat update 1.txt * | a19f1d5 merge dev with no-ff |\ \ | |/ | * 5ce53be update 1.txt add 1+1=2 |/ * b4d5931 add 2.txt * 4b25b16 commit 1.txt ====