Git常用命令

最近正在看Git,做个笔记,把常用的命令记下。

git init 初始化
git add <file> 将file添加到跟踪
git commit -m “..” 将修改提交到库,备注为”…”
git commit -a -m “…” 将所有跟踪文件全部提交
git status 查看状态
git rm <file> 移除文件,之后再commit提交
git mv <file1> <file2> 移动文件,之后再commit提交

git log 查看记录
git commit –amend 修改最后一次提交
git remote -v 查看远程仓库,-v显示地址
git remote add <shortname> <url> 添加远程仓库,别名为shortname
git fetch <remote-name> 从远程仓库抓取数据
git push <remote-name> <branch> 从本地branch推送到远程remote

git tag 显示所有标签
git tag -l <reg> 按照reg表达式来搜索标签
git tag -a <name> -m “..” 创建标签
git tag -a <name> <hash> 为某次提交打标签
git push remote —tags 推送本地所有标签

git branch <name> 从当前分支新建一个分支
git checkout <name> 切换到name分支
git checkout -b <name> 新建并切换到name分支
Gti merge <name> 将name分支合并到当前分支
git branch -d <name> 删除name分支
git branch -v 查看各分支最后一次提交

git fetch <remote-name> 从远程分支获取数据
git push <remote> [localbranch]:[remotebranch] 推送本地localbran到远程remotebranch,若localbranch参数为空则删除远程remotebranch分支
git chekcout -b <branch> <remote/branch> 从远程分支分化出一个新本地分支

git stash 暂存不想提交的修改
git stash list 查看暂存列表
git stash apply <stash-name> 应用暂存

git checkout —set-upstream <localbranch> <remote/branch> 本地分支localbranch跟踪远程分支branch
git clone <url> 克隆远程项目

git submodule add <url> <name> 创建子模块,保存到name目录
git submodule init 初始化子模块
git submodule update 从远程下载更新子模块

git archive [–format==tar|zip] [–prefix=<prefix>/] [-o file] <commit> [<path>…] 将commit提交记录中的path目录下的文件以format格式打包导出到file
git revert HEAD^ 撤消前前一次提交
git revert <hash> 撤消指定的版本
git revert —hard <commit> 彻底回退到某个版本