您的位置:首页 > 其它

总结的git操作命令小抄集

2016-11-15 16:52 141 查看
.gitignore 本地仓库主目录下,用于定义提交时忽略的文件

git add <file-name> 将修改或新增的文件存入暂存区

git reset HEAD <filen-ame> 将存入暂存区的文件取消暂存

git commit 提交代码

git commit -a 提交所有接受git跟踪的文件(节省了提交暂存区这一步)

git commit -m <annotation> 提交时添加注释

git commit --amend 重新提交(会覆盖上一次的提交)

git rm <file-name> 删除文件(包括本地目录与服务器)

git rm -cached <file-name> 只删除服务器文件,保留本地目录中的(适用于误提交了不该提交的缓存文件)

git status 详细的本地仓库文件状态

git status -s 以紧凑的格式输出

  ?? 表示未跟踪的文件
  A 表示新添加到暂存区的文件
   M 右M表示被修改了但暂未放入缓存区
  M 左M表示被修改了并已放入缓存区

git branch 查看分支列表

git branch <branch-name> 创建分支

git branch -d <branch-name> 删除分支,含有未合并的的提交时,该分支不允许删除

git branch -D <branch-name> 强制删除分支,含有丢失代码的风险

git branch -v 查看本地分支末次提交

git branch -vv 查看本地分支的指向及末次提交

git branch --merged 查看已合并到当前分支的分支

git branch --no-merged 查看未合并到当前分支的分支

git branch -u <origin-name>/<branch-name> 在当前分支设置或更改指向远程仓库的分支

git checkout <branch-name> 分支切换

git checkout -b <branch-name> 创建分支并切换到新分支

git checkout -b <branch-name> <origin-name>/<branch-name> 从远程拉取一个新分支到本地并切换到该分支

git checkout --track <origin-name>/<branch-name> 同上,快捷方式

git merge <branch-name> 将该分支合并到当前分支

git clone <url> 克隆一个远程仓库

git remote 查看已配置的远程仓库简写名

git remote -v 查看已配置的远程仓库url

git remote show <remote-name> 查看远程仓库的分支信息

git remote add <remote-name> <url> 添加一个新的远程仓库

git remote rename <old name> <new name> 修改远程仓库的简写名

git remote rm <remote-name> 删除一个远程仓库

git pull 从最初克隆的服务器上拉取代码合并到当前分支

git push <remote-name> <branch-name> 推送到远程仓库

git push <remote-name> --delete <branch-name> 删除远程仓库的分支

git fetch <remote-name> 从远程仓库获取所有更新
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: