git 操作

分支

新建分支 :git branch newBranchName  (复制当前分支)

新建分支并切换到新分支:git checkout -b newBranchName (复制当前分支)

切换分支:git checkout branchName

列出所有本地分支:git branch

列出所有远程分支:git branch -r

列出所有分支(本地和远程):git branch -a

将本地新建的分支推送到远程:git push [远程仓库名] [本地分支]:[远程分支]

     git push refs/heads/localBranchName:refs/heads/remoteBranchName ,或

     git push origin  localBranchName:remoteBranchName   或

     git push origin localBranchName

分支改名:

     git branch -m oldName newName  或  git branch -m newName(当前分支改名)

分支融合

    git merge branchName(将分支融合到当前分支)

拉取本地不存在的分支(并跟踪远程分支):

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

删除本地分支:

    git branch -d branchName 

    git branch -D branchName (未融合时)

删除远程分支(将空分支推向远程):

    git push origin :refs/heads/branchName 或

    git push origin :branchName

   git push origin --delete branchName


                     查看本地分支创建时间:git reflog show --date=iso branchName

                    查看分支所有信息:git reflog --date=local --all

                    当前分支跟踪远程分支(已关联仓库):git branch --set-upstream-to origin/remoteBranchName   git branch -u origin/remoteBranchName   

                    初次关联远程仓库后,git push -u origin master ,将本地当前分支关联到远程的master 分支上,以后就可以git push不指定参数了

                    提交所有已被管理的文件:git commit -a -m “信息”,跳过add操作

标签

新建标签:

    git tag tagName(给最新一次提交打上一个轻量标签)

    git tag -a tagName -m "描述" (给最新一次提交打上一个带注解的标签)

    git tag -a tagName -m "描述"  commitID (给某一次提交打上标签,查看commitID:git log --pretty=oneline,前几位字符即可)

     标签名最好不要和分支名相同,不然在操作时比较麻烦

查看所有标签: git tag

查看此标签下所修改的内容:git show tagName     (git show命令可以查看tag的详细信息,包括commit号等)

推送标签到远程:git push origin tagname

推送所有新增标签到远程:git push [origin] --tags

删除标签:git tag -d tagName

删除远程标签:git push origin :refs/tags/标签名 

切换到标签快照:git checkout tagName

根据标签新建分支:git checkout -b branch_name tag_name

从某次提交检出分支:git checkout -b branchname <commitId>

 

日志(提交历史)

git log

 

 

远程仓库

查看所有关联的远程仓:git remote -v

增加关联远程仓库:git remote add 本地仓库名 远程url

删除关联远程仓库:git remote remove 本地仓库名

远程仓库名一般是 origin(只有一个时,默认)

 

分别从两个远程仓库拉取和推送到两个远程仓库。

git pull origin master

git pull mirror master

git push origin master

git push mirror master

 

git 文档

https://git-scm.com/book/zh/v2/

posted @ 2019-01-11 18:39  zhanglw  阅读(184)  评论(0)    收藏  举报