forked from iicd/git-learner
		
	Compare commits
	
		
			13 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4bb20fac5f | |||
| 49c43b568f | |||
| 615467d28c | |||
| 31f7a8f26d | |||
| c59ecd2869 | |||
| 18f2b57018 | |||
| 5f7b2c5779 | |||
| 0a3fecc92e | |||
| 6a398dcde8 | |||
| f9e486b837 | |||
| 37a4decc83 | |||
| f2dd2b6d5c | |||
| a8029669af | 
							
								
								
									
										1
									
								
								Morgen.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								Morgen.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | Guten Morgen | ||||||
							
								
								
									
										1
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								README
									
									
									
									
									
								
							| @@ -1,3 +1,4 @@ | |||||||
| Hello. | Hello. | ||||||
| Nice to meet you. | Nice to meet you. | ||||||
| README | README | ||||||
|  | Nice to meet you too | ||||||
|   | |||||||
							
								
								
									
										49
									
								
								notes/2.10-git_clone.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								notes/2.10-git_clone.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | |||||||
|  | ## 2.10 git clone建立版本库克隆 | ||||||
|  |  | ||||||
|  | ### 2.10.1 | ||||||
|  |  | ||||||
|  | !()[https://www.worldhello.net/gotgit/images/git-clone-pull-push.png] | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git clone <repo> <dir> | ||||||
|  | git clone --bare <repo> <dir.git> # 不含工作区,不注册,不能用git fetch | ||||||
|  | git clone --mirror <repo> <dir.git> # 不含工作区,注册,可以用git fetch | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git push [<remote-repos> [refspec>]] | ||||||
|  | git pull [<remote-repos> [refspec>]] | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### 2.10.2 test | ||||||
|  |  | ||||||
|  | 对本地的git仓库进行backup | ||||||
|  | ```bash | ||||||
|  | git clone /path/to/my/workspace/demo /path/to/my/workspace/demo-backup | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 此时从主仓库到备用仓库中push是无法push的,因为备用仓库不是bare repo,用工作目录,直接更新会导致工作目录和最新的commit不一致,很奇怪。 | ||||||
|  |  | ||||||
|  | 此时应该从备用仓库中git pull。 | ||||||
|  |  | ||||||
|  | git clone会自动在本地仓库中说明远程仓库是在哪 | ||||||
|  | ```bash | ||||||
|  | git remote -v | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### 2.10.3 推送到裸仓库中 | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git push /path/to/bare/repo.git | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### 2.10.4 创建裸版本仓库 | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git init --bare demo-init.git | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git push /path/to/repo.git master:master #如果碰见没有指定的推送,需要加上master:master | ||||||
|  | ``` | ||||||
|  |  | ||||||
							
								
								
									
										3
									
								
								notes/2.11-git_repo_manage.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								notes/2.11-git_repo_manage.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,3 @@ | |||||||
|  | ## 2.11 git库管理 | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										51
									
								
								notes/2.9-change_history.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								notes/2.9-change_history.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,51 @@ | |||||||
|  | ## 2.9 改变历史 | ||||||
|  |  | ||||||
|  | ### 2.9.1 悔棋 | ||||||
|  |  | ||||||
|  | `git commit --amend -m` 会将当前的暂存区(staging area)中的更改与上一次的提交合并为一个新的提交,同时允许你修改提交信息。 | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git commit -amend -m "message" # 修改上次提交的message | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 添加一个误删的文件 | ||||||
|  | ```bash | ||||||
|  | git checkout HEAD^ -- <filename> # 从上次的提交恢复文件 | ||||||
|  | git status | ||||||
|  | git commit --amend -m "message" # 将当前的修改添加到上次的提交中 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### 2.9.2 多步悔棋 | ||||||
|  |  | ||||||
|  | 想要将最近的两个提交压缩为一个,并把提交说明改为“modify hello.h”,可以使用如下方法进行操作。 | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git reset --soft HEAD^^ # 重置到两次提交之前 | ||||||
|  | git status | ||||||
|  | git commit -m "modify hello.h" | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### 2.9.3 回到未来 git rebase | ||||||
|  |  | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git cherry-pick # 从众多的提交中挑选出一个提交应用在当前的工作分支中 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 去掉某个commit | ||||||
|  | ```bash | ||||||
|  | git checkout <commit> # 先切换到某次提交 | ||||||
|  | git cherry-pick <commit> # 输入之后的提交 | ||||||
|  | git checkout <branch> # 再切换回来 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 合并两次commit | ||||||
|  | ```bash | ||||||
|  | git checkout [<tag>|<commit>] | ||||||
|  | git reset --soft HEAD^^ # 向前移动两次 | ||||||
|  | git commit -C C # 提交,重用C提交的提交说明 | ||||||
|  | git cherry-pick E | ||||||
|  | git cherry-pick F | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										14
									
								
								notes/3.1_git_protocal.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								notes/3.1_git_protocal.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,14 @@ | |||||||
|  | ## 3.1 Git Protocal | ||||||
|  |  | ||||||
|  | ### 3.1.2 | ||||||
|  |  | ||||||
|  | 一般情况下,推送只允许“快进式”推送。 | ||||||
|  |  | ||||||
|  | 所谓快进式推送,就是要推送的本地版本库的提交是建立在**远程版本库相应分支的现有提交**基础上的,即远程版本库相应分支的最新提交是本地版本库最新提交的祖先提交。 | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git rev-list HEAD # 查看最新提交和历史提交 | ||||||
|  | git ls-remote origin # 显示远程版本库引用对应的哈希值 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										60
									
								
								notes/3.2_resolve_conflict.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								notes/3.2_resolve_conflict.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | |||||||
|  | ## 3.2 resolve conflict | ||||||
|  |  | ||||||
|  | ### 3.2.1 拉回操作中的合并 | ||||||
|  |  | ||||||
|  | pull操作的第一阶段,将共享版本库master分支的最新提交拉回到本地,并且更新到本地版本库特定的引用。 | ||||||
|  |  | ||||||
|  | 第二阶段,将本地分支master和共享版本库的本地跟踪分支origin/master进行合并操作。 | ||||||
|  |  | ||||||
|  | push操作,是将本地提交推送到共享版本库中。 | ||||||
|  |  | ||||||
|  | `git pull = git fetch + git merge` | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git merge [option...] <commit>... | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### 3.2.2 自动合并 | ||||||
|  |  | ||||||
|  | 多个用户修改了不同的文件/相同文件的不同部分,可以自动merge | ||||||
|  |  | ||||||
|  | 1. 多个用户修改了不同的文件 | ||||||
|  | 2. 相同文件的不同部分(开头,结尾) | ||||||
|  | 3. A用户移动文件,B用户编辑文件,自动merge会把编辑好的文件移动到对应位置 | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git fetch | ||||||
|  | git merge origin/master # origin/master就是共享版本库的本地分支 | ||||||
|  | git push | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### 3.2.3 逻辑冲突 | ||||||
|  |  | ||||||
|  | 存在逻辑冲突,需要在合并后进行单元测试 | ||||||
|  |  | ||||||
|  | ### 3.2.4 冲突解决 | ||||||
|  |  | ||||||
|  | git pull以后会提示冲突文件,如果忘记了用git status也可以 | ||||||
|  |  | ||||||
|  | git会自动把冲突的位置用七个<和七个=以及七个>标记出来,将他们删除掉,修改成想要的代码,就可以merge了 | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git log --oneline --graph -3 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ### 3.2.5 树冲突 | ||||||
|  |  | ||||||
|  | 文件处于不同状态,比如一个用户改名,另一个用户改成不同名字 | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git rm readme.txt | ||||||
|  | git rm doc/README.txt | ||||||
|  | git add README | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 本质上就是删除掉其他两个,留下来一个想要的 | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
		Reference in New Issue
	
	Block a user