初始准备
克隆仓库
git clone [url]
在当前目录新建一个Git代码库
git init
新建一个目录,并将其初始化为Git代码库
git init [project-name]
远程同步
增加一个新的远程仓库,并命名
git remote add [shortname] [url]
显示所有远程仓库
git remote -v
删除远程仓库与本地仓库关联名称
git remote rm origin
重新设置远程仓库地址
git remote set-url origin newAddress
关联远程仓库到新的本地仓库名称
git push origin -u new-name
上传本地指定分支到远程仓库
git push [remote] [branch]
取回远程仓库的变化,并与本地分支合并
git pull [remote] [branch]
下载远程仓库的所有变动
git fetch [remote]
增加/删除文件
添加当前目录的所有文件到暂存区
git add .
添加指定目录到暂存区,包括子目录
git add [dir]
添加指定文件到暂存区
git add [file1] [file2] ...
撤销
恢复暂存区的所有文件到工作区
git checkout .
amend补上遗漏文件(且不修改commit信息)
git commit –-amend –-no-edit
查看信息
查看本地master分支上最近x次commit
git log -<n>
查看指定分支的commit
git log [branch]
图形化显示分支信息(oneline),并显示分叉情况(graph)
git log --oneline --graph
查看指定文件涉及的commit(末尾 – [file or directory])
git log -- [file or directory]
查看指定时间范围内的commit
git log --since="1 years 2 month 3 weeks 4 days 5 hours 6 minutes 7 seconds ago"
git log --since="2019-6-11 12:12:12"
分支
合并指定分支到当前分支
git merge [branch]
合并指定commit到当前分支
git merge [commitID]
Tag 里程碑
查看本地tag
git tag
删除本地tag
git tag -d [tagName]