Git
发表于|更新于
|字数总计:2.6k|阅读时长:10分钟|阅读量:
Git
① Git概念
Git 是一个分布式版本控制工具,通常用来对软件开发过程中的源代码文件进行管理。通过Git 仓库来存储和管理这些文件,Git 仓库分为两种:①本地仓库:开发人员自己电脑上的 Git 仓库;②远程仓库:远程服务器上的 Git 仓库
	commit:提交,将本地文件和版本信息保存到本地仓库
	push:推送,将本地仓库文件和版本信息上传到远程仓库
	pull:拉取,将远程仓库文件和版本信息下载到本地仓库
 
② 工作区、暂存区、版本库
	版本库:前面看到的.git隐藏文件夹就是版本库,版本库中存储了很多配置信息、日志信息和文件版本信息等
	工作区:包含.git文件夹的目录就是工作区,也称为工作目录,主要用于存放开发的代码
	暂存区:.git文件夹中有很多文件,其中有一个index文件就是暂存区,也可以叫做stage。暂存区是一个临时保存修改文件的地方
 
③ git工作区文件状态
Git工作区中的文件存在两种状态:untracked  未跟踪(未被纳入版本控制)和 tracked 已跟踪(被纳入版本控制)
| Unmodified | 未修改状态 | 颜色 | 
| Modified | 已修改状态 | 红色 | 
| staged | 已暂存状态 | 绿色 | 
常用指令
Git全局设置
| 12
 3
 4
 5
 
 | git config --global user.name "cxz206015"
 git config --global user.email "206015cxz@gmail.com"
 
 git config --list
 
 | 
获取Git仓库
| 12
 3
 4
 
 | git init
 
 git clone < url >
 
 | 
本地仓库操作
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 
 | git status
 git add	<file>
 git add .
 git reset <file>
 git reset --hard <file>
 git commit
 git commit -a
 git commit -m "message" <file>
 git log
 
 | 
远程仓库操作
| 12
 3
 4
 5
 6
 
 | git remote							git remote -v
 git remote add <shortname> <url>
 git pull <remote-name> <branch>
 git push orign master
 --allow-unrelated-histories
 
 | 
分支操作
分支是动态的,通过git init 命令创建本地仓库时会默认创建一个 master 分支
| 12
 3
 4
 5
 6
 7
 
 | git branch							git branch -r
 git branch -a
 git branch <name>
 git checkout <name>
 git merge <name>
 
 
 | 
标签操作
标签是静态的
| 12
 3
 
 | git tag								git tag <name>
 git checkout -b <branch> <name>
 
 | 
总结
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 
 | git config --list
 git config --global core.editor vim
 git config core.ignorecase false
 git config --global user.name "YOUR NAME"
 git config --global user.email "YOUR EMAIL ADDRESS"
 
 
 git init
 git clone <url>
 git remote add origin git@github.com:用户名/仓库名.git
 git pull origin master
 git fetch origin
 
 
 git status
 git log
 git diff
 git branch
 
 
 git mv <old> <new>
 git rm <file>
 git rm --cached <file>
 
 
 git branch
 git branch -r
 git branch -a
 git branch <name>
 git checkout <name>
 git merge <name>
 
 
 git add .
 git add <file>
 
 git checkout master
 git switch dev
 git checkout -b dev
 
 git commit
 git commit -a
 git commit -m "first commit"
 git commit -am "first commit"
 git commit --amend
 
 
 git push
 git push origin master
 
 | 
 
全部指令
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 
 | git init                                                  git config --global user.name "xxx"
 git config --global user.email "xxx@xxx.com"
 git config --global color.ui true
 git config --global color.status auto
 git config --global color.diff auto
 git config --global color.branch auto
 git config --global color.interactive auto
 git config --global --unset http.proxy
 git clone git+ssh://git@192.168.53.168/VT.git
 git status
 git add xyz
 git add .
 git commit -m 'xxx'
 git commit --amend -m 'xxx'
 git commit -am 'xxx'
 git rm xxx
 git rm -r *
 git log
 git log -1
 git log -5
 git log --stat
 git log -p -m
 git show dfb02e6e4f2f7b573337763e5c0013802e392818
 git show dfb02
 git show HEAD
 git show HEAD^
 git tag
 git tag -a v2.0 -m 'xxx'
 git show v2.0
 git log v2.0
 git diff
 git diff --cached
 git diff HEAD^
 git diff HEAD -- ./lib
 git diff origin/master..master
 git diff origin/master..master --stat
 git remote add origin git+ssh://git@192.168.53.168/VT.git
 git branch
 git branch --contains 50089
 git branch -a
 git branch -r
 git branch --merged
 git branch --no-merged
 git branch -m master master_copy
 git checkout -b master_copy
 git checkout -b master master_copy
 git checkout features/performance
 git checkout --track hotfixes/BJVEP933
 git checkout v2.0
 git checkout -b devel origin/develop
 git checkout -- README
 git merge origin/master
 git cherry-pick ff44785404a8e
 git push origin master
 git push origin :hotfixes/BJVEP933
 git push --tags
 git fetch
 git fetch --prune
 git pull origin master
 git mv README README2
 git reset --hard HEAD
 git rebase
 git branch -d hotfixes/BJVEP933
 git branch -D hotfixes/BJVEP933
 git ls-files
 git show-branch
 git show-branch --all
 git whatchanged
 git revert dfb02e6e4f2f7b573337763e5c0013802e392818
 git ls-tree HEAD
 git rev-parse v2.0
 git reflog
 git show HEAD@{5}
 git show master@{yesterday}
 git log --pretty=format:'%h %s' --graph
 git show HEAD~3
 git show -s --pretty=raw 2be7fcb476
 git stash
 git stash list
 git stash show -p stash@{0}
 git stash apply stash@{0}
 git grep "delete from"
 git grep -e '#define' --and -e SORT_DIRENT
 git gc
 git fsck
 
 | 
忽略提交文件 .gitignore
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 
 | 
 target
 
 
 logs
 
 
 Thumbs.db
 
 
 .DS_Store
 
 
 .settings
 .project
 .classpath
 .log
 *.class
 
 
 .idea
 *.iml
 
 
 *.jar
 *.war
 *.ear
 /target
 
 |