`
砺雪凝霜
  • 浏览: 152030 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

git常用命令总结

    博客分类:
  • git
阅读更多

 

 

/**  使用场景: 恢复某个错误提交的commit */

git reset --hard log号                       回撤本地分支某个commit

 

 

/**  使用场景: git分支管理 */

 

 git fetch                                    # 把远程分支代码拉下来 

 

 git branch -r                                # 查看远程分支

 

 git checkout -b local_branch remote_branch   # 新建一个本地分支并与远程分支对应

 

 

 git add .                                    # 添加所有的代码

 

 git commit -m  'xxx'                         # commit 代码,并添加注释

 

 

/**  使用场景: 发布稳定版本后,打一个版本TAG */

 

 git tag -a v0.1.2 -m “0.1.2版本”           # 新建一个tag版本

 

 git push origin v0.1.2                       # 将v0.1.2标签提交到git服务器

 

 git push origin –tags                       # 将本地所有标签一次性提交到git服务器

 

git checkout -b branch tag              #切换到制定分支上的tag

 

 /** 代码提交常用命令*/

 git checkout -- filename      

 

 git reset  head   filename                  # 不提交该文件    

 

 git push origin   local_branch              # push代

 

 git -- amend                                # 合并2个commit

 

 git push origin local_develop              

 

 

/**  

使用场景: 切换到其它分支时,当前分支代码还不足以commit,这个时候可以把当前未修改的代码放                    stash区

*/

 

git stash               # 把代码保存到缓冲区stash list

 

git stash list          # 查看stash列表

 

git stash apply         # 解除stash并恢复未提交的变更(stash并不会清理)

 

git stash pop           # 解除stash并恢复未提交的变更(并清理stash)

 

git stash apply stash@{1}                   恢复第二个stash,statsh list 

 

 

/**  使用场景:当项目有多个分支时,在develop分支上修改了一个bug,其它分支也要修复该bug */

 

git cherry-pick [commit_hash]     # 在某个分支上,合并一个特定的commit

 

后续添加中...

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics