Compare commits
	
		
			15 Commits
		
	
	
		
			1fb3a5869a
			...
			old_practi
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4e8d0b6f8c | |||
| 11474a652c | |||
| 756beab203 | |||
| 711087a041 | |||
| cb4892dd9f | |||
| e073cddd87 | |||
| d68790956e | |||
| 4bdf9b82bc | |||
| dd95d391fb | |||
| c4dea21d20 | |||
| c4332b7c93 | |||
| 90fcb4ac61 | |||
| 32575fda96 | |||
| 17110b3072 | |||
| 3d733c9740 | 
							
								
								
									
										1
									
								
								hack-1.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								hack-1.txt
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | hello. | ||||||
							
								
								
									
										6
									
								
								notes/2.3-git_object.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								notes/2.3-git_object.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | |||||||
|  | ### 2.3.1 | ||||||
|  |  | ||||||
|  | git来说每次提交都创建一个commit对象,commit对象下有两个属性`tree` `parent`,用ID来表示,给定ID就能查看对象的类型是哪个,用`git cat-file -t <id>`来查看对象属性类型 | ||||||
|  | `commit` | ||||||
|  |  | ||||||
|  | `tree`对象下面对每个文件创建一个blob对象,blob对象里存的就是文件内容 | ||||||
							
								
								
									
										33
									
								
								notes/2.4-git_reset.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								notes/2.4-git_reset.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | |||||||
|  | ### 2.4.1 reset | ||||||
|  |  | ||||||
|  | `HEAD^`代表版本库中的上一次提交 | ||||||
|  |  | ||||||
|  | ### 2.4.2 reflog | ||||||
|  |  | ||||||
|  | 查看前五次提交的内容 | ||||||
|  | ``` | ||||||
|  | tail -5 .git/logs/refs/heads/master | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 查看最后五次提交内容 | ||||||
|  | ```text | ||||||
|  | git reflog show master | head -5 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 得到一个更容易记录的号码`branch@{#}`,来用`git reset --<way> branch@{#}`来记录 | ||||||
|  |  | ||||||
|  | ### 2.4.3 | ||||||
|  |  | ||||||
|  | `git reset [-- filename] `用HEAD重置暂存区,加上filename之后只重置单个文件 | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 1. HEAD指向的branch更换成指定的commit ID | ||||||
|  | 2. 暂存区中的内容替换成HEAD指向的branch的目录树 | ||||||
|  | 3. 把工作区替换成暂存区中的目录树 | ||||||
|  |  | ||||||
|  | `git reset --hard commit` 1 2 3 | ||||||
|  | `git reset --soft commit` 1 | ||||||
|  | `git reset --mixed commit` 1 2 | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										42
									
								
								notes/2.5_git_checkout.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										42
									
								
								notes/2.5_git_checkout.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,42 @@ | |||||||
|  | ## 2.5 Git Checkout | ||||||
|  |  | ||||||
|  | ### 2.5.1 HEAD reset = checkout | ||||||
|  |  | ||||||
|  | 查看当前的branch | ||||||
|  | ```bash | ||||||
|  | git branch -v | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | checkout到commit的父亲,使得head指针指向父提交,而不是branch | ||||||
|  | ```bash | ||||||
|  | git checkout <commit>^ | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 在detach模式下add,commit,HEAD都是指向最新的提交 | ||||||
|  |  | ||||||
|  | 之后再checkout到原来的分支,detach模式下的操作记录都会丢失 | ||||||
|  |  | ||||||
|  | ### 2.5.2 git merge | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git merge <commit> | ||||||
|  | ``` | ||||||
|  | 将<commit>提交合并到当前分支,这样做就可以把detach模式下的提交merge到当前分支上 | ||||||
|  |  | ||||||
|  | 合并以后的提交将有两个父提交 | ||||||
|  |  | ||||||
|  | ### 2.5.3 git checkout | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | 用法一: git checkout [-q] [<commit>] [--] <paths>... | ||||||
|  | 用法二: git checkout [<branch>] | ||||||
|  | 用法三: git checkout [-m] [[-b|--orphan] <new_branch>] [<start_point>] | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 第一种用法的`<commit>`是可选项,如果省略则相当于从暂存区(index)进行检出。reset的默认值是 HEAD,而checkout的默认值是暂存区。 | ||||||
|  |  | ||||||
|  | reset的目的是用HEAD重置暂存区,checkout是想暂存区中覆盖工作区的内容 | ||||||
|  |  | ||||||
|  | 第二种用法就是切换分支 | ||||||
|  |  | ||||||
|  | 第三种用法是新建分支 | ||||||
							
								
								
									
										34
									
								
								notes/2.6-git_stash.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								notes/2.6-git_stash.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | |||||||
|  | ## 2.6 | ||||||
|  |  | ||||||
|  | ### 2.6.1 | ||||||
|  |  | ||||||
|  | 用来查看stash列表 | ||||||
|  | ```bash | ||||||
|  | git stash list | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | 恢复进度 | ||||||
|  | ```bash | ||||||
|  | git stash pop | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git commit -m "message" # 执行提交 | ||||||
|  | git status -s # 查看状态 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git reset --soft HEAD^ #反悔提交 将HEAD指向当前提交的父提交 | ||||||
|  | git reset HEAD a/b/c # 将a/b/c目录下的文件撤出暂存区 | ||||||
|  | git reset 将所有的文件从stage中撤出 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git checkout -- welcome.txt # 清除welcome.txt的改动 | ||||||
|  | git clean -nd # 删除本地多余的目录和文件列表 | ||||||
|  | git clean -fd # 真正删除 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
							
								
								
									
										28
									
								
								notes/2.7-git_basic_op.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								notes/2.7-git_basic_op.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | |||||||
|  | ## 2.7 Git Basic Ops | ||||||
|  |  | ||||||
|  | ## 2.7.1 git tag | ||||||
|  |  | ||||||
|  | 给当前的进度打个标签 | ||||||
|  | ```bash | ||||||
|  | git tag -m "some message" <version-string> | ||||||
|  | git describe # 查看标签 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ## 2.7.2 Git 删除文件 | ||||||
|  | git  | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | rm *.txt  | ||||||
|  | git ls-files #本地删除不是真的删除,暂存库中还在,也就是删除的这个命令没有被添加到暂存库中 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git rm welcome.txt hack-2.txt #将文本文件从git中删除 | ||||||
|  | git status | ||||||
|  | git ls-files --with-tree=HEAD^ # 父节点中的文件还在 | ||||||
|  | ``` | ||||||
|  |  | ||||||
|  | ```bash | ||||||
|  | git add -u #将版本库中的本地文件的变更记录到暂存区中 | ||||||
|  | ``` | ||||||
|  |  | ||||||
							
								
								
									
										0
									
								
								notes/detached-commit.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								notes/detached-commit.txt
									
									
									
									
									
										Normal file
									
								
							
		Reference in New Issue
	
	Block a user