zoukankan      html  css  js  c++  java
  • git Doc

    https://www.git-scm.com/docs/git-pull

    https://www.runoob.com/git/git-pull.html

    https://www.yiibai.com/git/git_pull.html

    https://www.runoob.com/git/git-remote.html

    记录】Git pull(拉取),push(上传)命令整理(详细)

    工程师小C的小店我也想开通小店
    Python编程三剑客:Python编程从入门到实践第2版+快速上手第2版+极客编程(套装共3册)

    作者:[美] 埃里克·马瑟斯(Eric Matthes)出版社:人民邮电出版社

    好评:100% 销售量:2¥195

    更多

      前言:博主最近在学习git命令,因为git是一个非常好用的分布式版本管理工具,功能比svn强大,与SVN不同点是Git去中心化,每一个分支都是一个中心,并且支持本地仓库存储,像如今很多大公司都用git做版本控制。话不多说,具体命令整理如下:

    git拉取远程代码

    git clone  https://xxx.git
    

      

    git拉取远程指定分支下代码(-b  分支名称)

    git clone -b v2.8.1 https://xxx.git
    

      

    初始化一个本地仓库,在同级目录下会出现一个隐藏的.git文件

    git init
    

      

    查看git的配置信息

    git config -l
    

      

    git配置本地仓库的userName(必须)

    git config user.name 'Lee'
    

      

    git配置本地仓库的邮箱(必须)

    git config user.email '12345@qq.com'
    

      

    三级文件配置路径:

    1.  
      .git/config
    2.  
      /.gitconfig #当前用户目录
    3.  
      /etc/gitconfig #git安装目录

    本地提交到git索引(缓存)中

    1.  
      git add . #把新增的、修改的都加到缓存
    2.  
       
    3.  
      git add -A #把新增、和修改的、和删除的都加到缓存

      

    本地从缓存中加到文件库(repository)中

    git commit -m '版本描述'  #提交到文件库
    

     

    本地一件提交到文件库中

    git commit -am '版本描述'   #一步完成提交
    

      

    查看当前git状态信息(查看是否有文件未提交)

    git status
    

      

    git中的三类文件

    1.  
      被追踪的(tracked):已经加入文档库
    2.  
      不被追踪的(untracked):没有加入文档库
    3.  
      忽略的(ignored):忽略那些不需要管理的文件夹或文件

      

    git新建忽略文件  目录下建立一个.gitignore文件(可以有多个,影响范围当前文件及子文件)

    touch .gitignore
    

      

    .gitignore文件忽略内容demo

    1.  
      # Maven #
    2.  
      target/
    3.  
       
    4.  
      # IDEA #
    5.  
      .idea/
    6.  
      *.iml
    7.  
       
    8.  
      # Eclipse #
    9.  
      .settings/
    10.  
      .classpath
    11.  
      .project

      

    注意:新建的一个忽略文件,为什么没有生效

    答:可能是因为你的缓存区已经有忽略的文件了,所以需要先清空缓存区里的文件,重新add和commit操作

    删除缓存区所有文件命令

    git rm -r --cached .   #主要这个点一定要写
    

      

    重新add到缓存区

    git add .
    

      

    每一次commit都是一个提交点,唯一标识SHA1的ID,ID可使用前4至7个数字表示

    查看git的日志信息

    git log
    

      

    给提交点打标签  git tag -a v0.2 4a80f64(提交点SHA1的ID的前7位)

     git tag -a tagV1 d819565b     #提交点SHA1的ID的前7位

     

    回车之后会有输入tag内容的界面,然后像linux一样 点击 i 编辑   输入信息后  esc 然后 :wq 保存退出

    简化git日志输出格式

    git log --oneline
    

      

    显示主分支和自分支git日志 (前面会多个星号)

    git log --oneline --graph
    

      

    查看本地添加了哪些远程分支地址

    git remote
    

      

     查看本地添加了哪些远程分支地址(详细)

    git remote -v
    

      

     删除本地指定的远程地址

    git remote remove origin
    

      

    添加远程地址

    git remote add origin https://xxxxxxxxxxxx.git
    

        

    分支:分支意味着你可以从开发主线(master)上分离开,在不影响主线的同事继续工

    1.  
      git branch #列出当前开发所有分支(默认会有master)
    2.  
      git branch king #创建一个king的分支(最新提交点)
    3.  
      git branch king 提交点 # 创建一个king的分支(指定提交点)
    4.  

      git branch -d -r <branchname> # 删除远程分支,删除后还需推送到服务器
      git push origin:<branchname>  # 删除后推送至服务器

    5.  
      git branch -d king #删除king分支
    6.  
       
    7.  
       
    8.  
      git checkout king #切换至king分支
    9.  
       
    10.  
      git checkout master
    11.  
      git merge king #合并分支king和主干master,合并后的提交点属于主干master

    本地分支重命名

    git branch -m <oldbranch> <newbranch> #重命名本地分支
    

      

    查看本地和远程的所有分支

    git branch -a     # 查看本地和远程的所有分支
    

      

    查看远程所有分支

    git branch -r # 查看远程所有分支
    

      

    重命名远程分支:

    1、删除远程待修改分支
    2、push本地新分支到远程服务器

     head节点代表最新的commit  显示head 信息

    git show HEAD
    

      

    回退:git reset 选项 提交点(选项:--hard表示全恢复  提交点:可用ID或标签) 

    git reset --hard v0.1
    

      

     查询所有提交点

    git reflog   #回退后需要反悔的话,需要通过此命令查找到所有操作的提交点
    

      

    合并分支的起始点(不推荐) 

    1.  
      git checkout master
    2.  
      git rebase reking #合并分支reking和主干master,合并后的提交点属于主干master

      clone 克隆远程文件

    git clone "远程地址"  "本地文件名称"
    

      

    push   推送本地修改分支至远程git仓库

    git push -u origin feature-wxDemo
    

      

    fetch与pull

    fetch是将远程主机的最新内容拉到本地,不进行合并

    git fetch origin master
    

      

    pull 则是将远程主机的master分支最新内容拉下来后与当前本地分支直接合并 fetch+merge

    git pull origin master

    如果远程分支是与当前分支合并,则冒号后面的部分可以省略。如下:

    git pull origin master:feature-wxDemo    #git pull <远程主机名> <远程分支名>:<本地分支名>

      

    统计文件改动

    git diff --stat master origin/master  #git diff <local branch> <remote>/<remote branch> 
    

     

    git分支说明

    1.  
      Production分支(主线分支用于发版,不会直接改)
    2.  
      Master分支,这个分支只能从其他分支合并,不能在这个分支直接修改
    3.  
       
    4.  
      Develop分支(开发分支)
    5.  
      这个分支是我们是我们的主开发分支,包含所有要发布到下一个Release的代码,这个主要合并与其他分支,比如Feature分支
    6.  
       
    7.  
      Feature分支(新功能分支)
    8.  
      这个分支主要是用来开发一个新的功能,一旦开发完成,我们合并回Develop分支进入下一个Release
    9.  
       
    10.  
      Release分支(偏向测试)
    11.  
      当你需要一个发布一个新Release的时候,我们基于Develop分支创建一个Release分支,完成Release后,我们合并到Master和Develop分支
    12.  
       
    13.  
      Hotfix分支(紧急bug发布)
    14.  
      当我们在Production发现新的Bug时候,我们需要创建一个Hotfix, 完成Hotfix后,我们合并回Master和Develop分支,所以Hotfix的改动会进入下一个Release

      

     比较本地分支与git 主分支差异情况

    git diff --stat feature-wxAgentIm origin/master  # git diff <local branch> <remote>/<remote branch>
    

      

     git中一些选项解释(重要):

    1.  
      -d
    2.  
      --delete:删除
    3.  
       
    4.  
      -D
    5.  
      --delete --force的快捷键
    6.  
       
    7.  
      -f
    8.  
      --force:强制
    9.  
       
    10.  
      -m
    11.  
      --move:移动或重命名
    12.  
       
    13.  
      -M
    14.  
      --move --force的快捷键
    15.  
       
    16.  
      -r
    17.  
      --remote:远程
    18.  
       
    19.  
      -a
    20.  
      --all:所有

      

    以上整理希望能帮助到你。

    转载于:https://www.cnblogs.com/wbl001/p/11495110.html

    #################################################################################################################################

    git解决冲突与merge

    全速前行 2015-04-25 13:17:44 146679 收藏 1
    分类专栏: SCM 文章标签: git-merge git冲突解决 CONFLICT
    版权
    git冲突的场景与其他SCM工具一样,我在这边修改了文件a,同事也修改了文件a。同事比我先提交到仓库中,那么我pull代码时就会报错:

    $ git pull
    remote: Counting objects: 39, done.
    remote: Compressing objects: 100% (30/30), done.
    remote: Total 39 (delta 13), reused 0 (delta 0)
    Unpacking objects: 100% (39/39), done.
    From https://code.csdn.net/lincyang/androidwidgetdemo
    d3b2814..5578b8c master -> origin/master
    Updating d3b2814..5578b8c
    error: Your local changes to the following files would be overwritten by merge:
    app/src/main/AndroidManifest.xml
    app/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.java
    Please, commit your changes or stash them before you can merge.
    Aborting
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    而此时我又不顾这个错误,将我的代码add并commit,然后push时报如下错:

    To https://code.csdn.net/lincyang/androidwidgetdemo.git
    ! [rejected] master -> master (non-fast-forward)
    error: failed to push some refs to 'https://code.csdn.net/lincyang/androidwidgetdemo.git'
    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.
    1
    2
    3
    4
    5
    6
    7
    8
    然后我有执行了git pull:

    $ git pull
    Auto-merging app/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.java
    CONFLICT (content): Merge conflict in app/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.java
    Auto-merging app/src/main/AndroidManifest.xml
    CONFLICT (content): Merge conflict in app/src/main/AndroidManifest.xml
    Automatic merge failed; fix conflicts and then commit the result.
    1
    2
    3
    4
    5
    6
    那么既然两个文件冲突,我就可以借助mergetool来搞定它。我安装了meld作为代码比对工具,那么它理所当然也就成为我的mergetool了。

    $ git mergetool

    This message is displayed because 'merge.tool' is not configured.
    See 'git mergetool --tool-help' or 'git help config' for more details.
    'git mergetool' will now attempt to use one of the following tools:
    meld opendiff kdiff3 tkdiff xxdiff tortoisemerge gvimdiff diffuse diffmerge ecmerge p4merge araxis bc3 codecompare emerge vimdiff
    Merging:
    app/src/main/AndroidManifest.xml
    app/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.java

    Normal merge conflict for 'app/src/main/AndroidManifest.xml':
    {local}: modified file
    {remote}: modified file
    Hit return to start merge resolution tool (meld):

    Normal merge conflict for 'app/src/main/java/com/linc/skill/screenswitch/ScreenSwichActivity.java':
    {local}: modified file
    {remote}: modified file
    Hit return to start merge resolution tool (meld):
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    merge完成后,执行git status发现有些文件做了修改,那么把这些文件提交 吧,就把这次commit作为一次merge操作吧。

    $ git commit -m "merge"
    [master 978aa1f] merge
    $ git push
    Counting objects: 64, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (25/25), done.
    Writing objects: 100% (33/33), 3.81 KiB | 0 bytes/s, done.
    Total 33 (delta 15), reused 0 (delta 0)
    To https://code.csdn.net/lincyang/androidwidgetdemo.git
    5578b8c..978aa1f master -> master
    $ git pull
    Already up-to-date.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    至此,本次冲突解决完毕。

    如果希望保留生产服务器上所做的改动,仅仅并入新配置项, 处理方法如下:

    git stash
    git pull
    git stash pop
    1
    2
    3
    参考:
    http://www.cnblogs.com/sinojelly/archive/2011/08/07/2130172.html
    ————————————————
    版权声明:本文为CSDN博主「全速前行」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/lincyang/article/details/45269491

  • 相关阅读:
    HDU 2955(01背包问题)
    POJ 2250(LCS最长公共子序列)
    POJ 3356(最短编辑距离问题)
    HDU 1069 Monkey and Banana(LIS最长上升子序列)
    POJ
    HDU 2955(0-1背包问题)
    HDU2602 (0-1背包问题)
    hdu1003 Max Sum(经典dp )
    C题
    D题(贪心)
  • 原文地址:https://www.cnblogs.com/pengmn/p/14665926.html
Copyright © 2011-2022 走看看