工作常见的git命令

 Git创建项目仓库:

  1、git init 初始化

  2、git remote add origin url 关联远程仓库

  3、git pull  拉取远程仓库到本地  相当于(git fetch+git merge)

  4、git fetch    获取远程仓库中所有的分支到本地

常规操作:

  1、git push orgin  BranchName  推送本地分支到远程仓库

  2、git rm -r --cached 文件/文件夹名字  取消文件被版本控制

  3、git reflog  获取执行过的命令

  4、git log --graph 查看分支合并图

扫描二维码关注公众号,回复: 8367942 查看本文章

  5、git merge --no-ff -m '合描述' 分支名   不使用Fast forward方式合并,采用这种方式合并可以看到合并记录

  6、git check -ignore -v 文件名  查看忽略规则

分支操作:

 1、git branch 创建分支

 2、git branch -b创建并切换到新建的分支上

 3、git checkout 切换分支

 4、git branch 查看分支列表

 5、git branch -v 查看所有分支的最后一次操作

 6、git branch -vv 查看当前分支

 7、git branch -b BranchName  origin/BranchName    创建远程分支到本地

 8、git branch --merged 查看别的分支和当前分支合并过的分支

 9、git branch --no-merged 查看未与当前分支合并的分支

 10、git branch -D BranchName     删除本地分支

 11、git branch -r -D origin/BranchName  删除本地的远程分支

 12、git push origin -d BranchName  远程删除git服务器上的分支

 13、 git merge BranchName 合并分支到当前分支上

 14、 git  rebase 变基

暂存操作

 1、git stash  暂存当前修改

 2、git stash apply 恢复最近的一次暂存

 3、git stash pop  恢复暂存并删除暂存记录

 4、git stash list  查看暂存列表

 5、git stash drop   暂存名(例如:stash@{0})  移除某次暂存   

 6、git stash clear  清除暂存

回退操作

 1、git reset --hard HEAD^   回退到上一个版本

 2、git reset --hard  (commit_id)  回退到某个版本

 3、git checkout -- file  撤销修改的文件(如果文件加入到了暂存区,则回退到暂存区的,如果文件加到了版本库,则还原至加入版本库之前的状态)

 4、git reset HEAD file 撤回暂存区的文件到工作区

标签操作

 1、git tag 标签名  添加标签(默认对当前版本)

 2、git tag 标签名 commit_id  对某一提交记录打标签

 3、git tag  -a 标签名 -m '描述' 创建新标签并添加备注

 4、git tag  列出所有标签列表

 5、git show 标签名  查看标签信息

 6、git tag -d 标签名 删除本地标签

 7、git  push origin 标签名 推送标签到远程仓库

 8、git  push origin --tags 推送所有标签到远程仓库

 9、git  push origin :refs/tags/标签名  从远程仓库删除标签

猜你喜欢

转载自www.cnblogs.com/xiaofeng-fu/p/12121771.html