• git 常用指令


     

    git branch用法总结

    2011-10-30 19:37 12724人阅读 评论(1) 收藏 举报

    branchgit

    git branch
       
       git branch 不带参数:列出本地已经存在的分支,并且在当前分支的前面加“*”号标记,例如:
       #git branch
    * master
       newbranch

       git branch -r 列出远程分支,例如:
       #git branch -r
       m/master -> origin_apps/m1_2.3.4
       origin_apps/hardware/test
       origin_apps/m1
       origin_apps/m1_2.3.4
       origin_apps/master

       git branch -a 列出本地分支和远程分支,例如:
       #git branch -a
       * master
       newbranch
       remotes/m/master -> origin_apps/m1_2.3.4
       remotes/origin_apps/hardware/test
       remotes/origin_apps/m1
       remotes/origin_apps/m1_2.3.4
       remotes/origin_apps/master

       git branch 创建一个新的本地分支,需要注意,此处只是创建分支,不进行分支切换,例如:
       #git branch newbranch2
       #git branch
       * master
       newbranch
       newbranch2
       当前的分支依然是master,不进行切换。

       git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名。

       git branch -d | -D branchname 删除branchname分支

       git branch -d -r branchname 删除远程branchname分支


    例子:
    git help branch中的一个例子:
       $ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
       $ cd my2.6
       $ git branch my2.6.14 v2.6.14   
       $ git checkout my2.6.14      
       第三行符合git branch <branchname> [<start-point>]的格式,即以v2.6.14为start-point,创建新的本地分支branchname。

    取得Git仓库

    初始化一个版本仓库

    git init

    Clone远程版本库

    git clone git@xbc.me:wordpress.git

    添加远程版本库origin,语法为 git remote add [shortname] [url]

    git remote add origin git@xbc.me:wordpress.git

    查看远程仓库

    git remote -v

    提交你的修改

    添加当前修改的文件到暂存区

    git add .

    如果你自动追踪文件,包括你已经手动删除的,状态为Deleted的文件

    git add -u

    提交你的修改

    git commit –m &quot;你的注释&quot;

    推送你的更新到远程服务器,语法为 git push [远程名] [本地分支]:[远程分支]

    git push origin master

    查看文件状态

    git status

    跟踪新文件

    git add readme.txt

    从当前跟踪列表移除文件,并完全删除

    git rm readme.txt

    仅在暂存区删除,保留文件在当前目录,不再跟踪

    git rm –cached readme.txt

    重命名文件

    git mv reademe.txt readme

    查看提交的历史记录

    git log

    修改最后一次提交注释的,利用–amend参数

    git commit --amend

    忘记提交某些修改,下面的三条命令只会得到一个提交。

    git commit –m &quot;add readme.txt&quot;

    git add readme_forgotten

    git commit –amend

    假设你已经使用git add .,将修改过的文件a、b加到暂存区

    现在你只想提交a文件,不想提交b文件,应该这样

    git reset HEAD b

    取消对文件的修改

    git checkout –- readme.txt

    基本的分支管理

    创建一个分支

    git branch iss53

    切换工作目录到iss53

    git chekcout iss53

    将上面的命令合在一起,创建iss53分支并切换到iss53

    git chekcout –b iss53

    合并iss53分支,当前工作目录为master

    git merge iss53

    合并完成后,没有出现冲突,删除iss53分支

    git branch –d iss53

    拉去远程仓库的数据,语法为 git fetch [remote-name]

    git fetch

    fetch 会拉去最新的远程仓库数据,但不会自动到当前目录下,要自动合并

    git pull

    查看远程仓库的信息

    git remote show origin

    建立本地的dev分支追踪远程仓库的develop分支

    git checkout –b dev origin/develop

    • HEAD指向的版本就是当前版本,因此,Git允许我们在版本的历史之间穿梭,使用命令git reset --hard commit_id
    • 穿梭前,用git log可以查看提交历史,以便确定要回退到哪个版本。
    • 要重返未来,用git reflog查看命令历史,以便确定要回到未来的哪个版本。

    git reset命令既可以回退版本,也可以把暂存区的修改回退到工作区。当我们用HEAD时,表示最新的版本。

    回滚:
    git reset --hard HEAD^
    git reset --hard 3628164
    操作过程
    git reflog
    git push origin :branch-name

    冒号前面的空格不能少,原理是把一个空分支pushserver上,相当于删除该分支。
    
    

    git 常用命令(精装版)

    列出本地存在的分支

    git branch

    git branch -a  本地和远程

    git branch -r 远程分支

    创建分支:

    git branch  <newbranch>

    git checkout <newbranch>

    等同:

    git checkout -b  <newbranch>

    重命名分支

    git branch -m | -M oldbranch newbranch 重命名分支,如果newbranch名字分支已经存在,则需要使用-M强制重命名,否则,使用-m进行重命名

    删除分支:  

    git branch -d | -D branchname 删除branchname分支
    git branch -d -r branchname 删除远程branchname分支

    添加远程版本库origin,语法为 git remote add [shortname] [url]

    git remote add origin git@xbc.me:wordpress.git

    查看远程仓库

    git remote -v

    将本地文件推送到远程库

    $ git push origin test:master         // 提交本地test分支作为远程的master分支

    $ git push origin test:test              // 提交本地test分支作为远程的test分支

  • 相关阅读:
    14.使用nodejs将规定格式的txt转化为json数据
    13.resize妙用(书上看到的)
    12.写了一个怪怪的边框
    11.一起来抄一个小小的提示菜单
    UI02-textfiled.按钮 uibutton
    UI01-UIview UIlable的属性
    OC9-内存管理
    OC8-属性 KVC是键值编码
    OC7-‍ 类目,延展 协议代理。
    OC6-block-函数指针
  • 原文地址:https://www.cnblogs.com/qlchan/p/3999818.html
Copyright © 2020-2023  润新知