目录
基础配置命令
配置个人用户名称,比如名称:abc
git config --global user.name "abc"
配置个人电子邮箱地址,比如:abc@163.com
git config --global user.email abc@163.com
查看配置信息,所有信息
git config --list
查看具体配置信息,其他配置信息类似
git config use.name
配置差异分析工具 --- vimdiff
git config --global merge.tool vimdiff
新建本地代码仓库
在当前文件夹中(可新建),使用命令初始化本地仓库
git init [project-name]
[project-name] 指定一个文件夹,并初始化为本地仓库
在远程仓库中,拉取下来一个仓库
git clone [url]
这里的 url 是远程仓库对应的url
文件操作
将文件添加到暂存区,如:a.txt 文件
git add [file1] [file2] ...
git add a.txt
[file1] 文件的名字
将当前目录的所有文件添加到暂存区
git add .
将目录添加到暂存区(包括子目录),如:abc 目录
git add [dir]
git add abc
[dir] 目录的名字
提交文件,从暂存区提交到工作区
git commit [file1] [file2] ... [message]
git commit a.txt
[file1] 文件的名字
[message] 可以加上提交的分支
删除工作区文件,并且将这次删除放入暂存区
git rm [file1] [file2] ...
git rm a.txt
移动或重命名工作区文件,并且将这个改名后的文件放入暂存区
git mv [file-original] [file-renamed]
git mv a.txt newa.txt
查看信息
查看仓库当前的状态,显示变更的文件
git status [-s]
[-s] 参数用来获取简短的输出结果。
显示当前分支的版本历史
git log [--oneline] [--reverse]
[--oneline] 选项用来查看历史记录的简洁版本
[--reverse] 参数用来逆向显示所有日志。
查看指定文件修改日记
git blame file
git blame a.txt
查看比较差异性
git diff file
fit diff a.txt
远程仓库同步
增加一个新的远程仓库,并命名别名
git remote add [shortname] [url]
[shortname] 远程仓库 url 别名
[url] 远程仓库 url
显示某个远程仓库的信息
git remote show [remote]
[remote] 远程仓库url地址别名
本地文件上传远程仓库,并指定分支
git push [remote] [branch]
[remote] 远程仓库url地址别名
[branch] 指定远程仓库的分支
从远程仓库拉取代码
fetch方式:不会自动合并本地分支代码
git fetch [remote] [branch]
pull方式:自动合并本地代码
git pull [remote] [branch]
分支操作
创建分支,但依然停留在当前分支
git branch [branch-name]
git branch dev
[branch-name] 分支的名字
切换分支,并更新工作区
git checkout [branch-name]
git checkout dev
[branch-name] 分支的名字
列出所有分支
git branch [-r] [-a]
[-r] 列出所有远程分支
[-a] 列出所有本地分支和远程分支
删除分支
git branch -d [branch-name]
[branch-name] 分支的名字
标签操作
列出所有的标签
git tag
新建一个标签
git tag [-a] [tag]
[-a] 选项可以创建一个带注解的标签
[tag] 标签的名字
查看此版本所修改的内容
git show [tag]
[tag] 标签的名字
删除标签
git tag -d [tag]
[tag] 标签的名字
其他
生成SSh秘钥命令
ssh-keygen -t rsa
生成秘钥位置,默认:c:/users/.ssh/id_rsa