git常用命令

一、获取远程分支

git clone命令默认会把远程仓库整个给clone下来,但是只会在本地建立远端git库的当前工作分支。

如果想获取其它分支信息,需要使用”git branch –r” 来查看, 如果需要将远程的其它分支代码也获取过来,可以使用命令:

git checkout -b 本地分支名 远程分支名

其中,远程分支名为git branch –r所列出的分支名, 一般是诸如“origin/分支名”的样子。如果本地分支名已经存在, 则不需要“-b”参数。

 或者使用-t参数,它默认会在本地建立一个和远程分支名字一样的分支

git checkout -t origin/consult

二、撤销当前所有提交

git reset --hard HEAD

  

三、查看提交历史记录

gitk

  

git常用命令

参考:http://www.scmlife.com/thread-22562-1-1.html

branch:
重命名:git branch -m old_branch new_branch 删除分支:git push origin :old_branch # Delete the old branch 本地分支同步到远程:git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
创建分支: git branch mybranch
切换分支: git checkout mybranch
创建并切换分支: $ git checkout -b mybranch
更新master主线上的东西到该分支上:$git rebase master
切换到master分支:$git checkout master
提交:git commit -a
对最近一次commit的进行修改:git commit -a –amend
commit之后,如果想撤销最近一次提交(即退回到上一次版本)并本地保留代码:git reset HEAD^
删除分支: $ git branch -d mybranch
强制删除分支: $ git branch -D mybranch
查看各个分支最后一次提交: $ git branch -v
查看哪些分支合并入当前分支: $ git branch –merged
查看哪些分支未合并入当前分支: $ git branch –no-merged
更新远程库到本地: $ git fetch origin
推送分支: $ git push origin mybranch
取远程分支合并到本地: $ git merge origin/mybranch
取远程分支并分化一个新分支: $ git checkout -b mybranch origin/mybranch
删除远程分支:$ git push origin :mybranch
tag

git 下打标签其实有2种情况

  (1): 轻量级的

  它其实是一个独立的分支,或者说是一个不可变的分支.指向特定提交对象的引用.

  (2):带附注的

  实际上是存储在仓库中的一个独立对象,它有自身的校验和信息,包含着标签的名字,标签说明,标签本身也允许使用 GNU Privacy Guard (GPG) 来签署或验证,电子邮件地址和日期,一般我们都建议使用含附注型的标签,以便保留相关信息.所以我们推荐使用第二种标签形式.

      创建:创建了本地一个版本 V1.2 ,并且添加了附注信息 'WebSite version 1.2' :git tag -a V1.2 -m 'WebSite version 1

  查看: git tag

  查看(带附注信息):git show V1.2

  推送到远程:git push origin --tags

  删除(本地tag):git tag -d V1.2

  删除本地后,push到线上,删除线上:git push origin :refs/tags/V1.2

  获取远程版本:git fetch origin tag V1.2

参考:https://www.cnblogs.com/wuyifu/p/5867567.html


原文地址:https://www.cnblogs.com/karila/p/9235371.html