zoukankan      html  css  js  c++  java
  • GIT

    Learning GIT from an example

    GIT  

    #表示注释、说明,蓝色表输入命令

    mkdir first.git #

    git init  #初始化倉庫

    #copy some files to this dir

    git add .  #添加所有文件

    #git add ./path/all/

    git commit -m "init"   #生成commit

    pwd

    #/home2/floyd.peng/testdir/first.git

    #and the user is floyd.peng password is ****

    #then how to clone this depository

    #we use ssh protocol to protect our data,clone the remote git depository and rename it to second.git

    git clone ssh://floyd.peng@172.17.144.4/home2/floyd.peng/testdir/first.git second.git

    #howerver we can also use  http or git replace ssh,just like the cmd below

    #git clone http://www.kernel.org/pub/scm/git/floyd.git

    #git clone git://www.kernel.org/pub/scm/git/floyd.git

    #git clone floyd.peng@http://www.kernel.org/pub/scm/git/floyd.git

    #we create a branch named floyd in first.git, and checkout to the new branch

    git branch floyd

    git checkout floyd

    cat "this is the new content">new

    git add new

    git commit -m "add new  into the depository"

    #then how to clone branch floyd from first.git,if ignore '-b floyd',it will clone the branch which is active now in the first.git

    git clone -b floyd ssh://floyd.peng@172.17.144.4/home2/floyd.peng/testdir/first.git third.git

    #then we create a branch in second.git which named hello

    git branch hello

    git checkout hello

    #notice that first.git is newer than second.git, then try to update the depository by using git pull(now second.git is on branch hello ,not master)

    git pull

    #then errors happen

    #################error info#########################
    
    floyd.peng@172.17.144.4's password:
    You asked me to pull without telling me which branch you
    want to merge with, and 'branch.hello.merge' in
    your configuration file does not tell me either. Please
    name which branch you want to merge on the command line and
    try again (e.g. 'git pull <repository> <refspec>').
    See git-pull(1) for details on the refspec.
    
    #################error info#########################

    #the how to solve those errors,if we try this,no errors

    git pull ssh://floyd.peng@172.17.144.4/home2/floyd.peng/testdir/first.git master

    #above cmd tells git to clone master(remote)

    #also we can do it like this

    git config branch.master.remote origin

    git config branch.master.merge refs/heads/master

    #we can also solve this problem by editing the config file under the .git

    #we can add this into the config

    [branch "hello"]
    remote = origin
    merge = refs/heads/master

    #summary,about the error happened above,branch hello is new,he doesnot know how to communicate with the remote git depository

    #how to revoke the changes  or the commits

    #git reset --hard commit_sha    

    #revoke the changes completely

    #git reset --soft commit_sha

    #only remain changes the files 

    #look our commit logs 

    git log --color

    #############commit log###############################
    
    commit 4b64a903ca340cc94fdead35a21b7c6b31db6aa7
    Author: floyd.peng <floyd.peng@dniserver.dnish.net>
    Date: Wed Nov 7 15:02:17 2012 +0800
    
    add new
    
    commit 9153154c8466e6a281289fbe200a3c89618258ec
    Author: floyd.peng <floyd.peng@dniserver.dnish.net>
    Date: Wed Nov 7 14:31:39 2012 +0800
    
    init
    
    #############commit log###############################

    #git log --pretty=format:"%H,%ar,%an,%s"    show our cimmit log as designed format

    #%H~hash,%ar~author,%an~eidt time,%s~commit direction

    #back to the commit 9153154c8466e6a281289fbe200a3c89618258ec

    git reset --hard 9153154c8466e6a281289fbe200a3c89618258ec

    git reset --soft 9153154c8466e6a281289fbe200a3c89618258ec

    #the difference between hard and soft is that the latter one will remain the code changes,while the former one wouldnot

     

    #how to generate patches

    #make commit 4b64a903ca340cc94fdead35a21b7c6b31db6aa7 into a patch

    git format-patch -u -1

    #and the generate patch is "0001-add-new.patch"

    #apply the patch 

    git apply 0001-add-new.patch

    #then we need to add and commit the change file

    #about git format-patch,we can use it like this

    #git format-patch commit_id1 commit_id2

    #git format-patch tag1 tag2

    #how to generate tag for commmit 9153154c8466e6a281289fbe200a3c89618258ec

    git tag tag_name 9153154c8466e6a281289fbe200a3c89618258ec

     

    #now if we have three commit as below

    #f5ba3632e9007d67515a06dceefd795f3d46c351

    #9153154c8466e6a281289fbe200a3c89618258ec

    #719e01dbf3abca416d8e406cbf1e1d77f92bb7a7

    #and we name them as third,second,first

    git format-patch 9153154c8466e6a281289fbe200a3c89618258ec

    #this cmd will generate patch for commit second and commit third,not include commit first

    git format-patch -1 9153154c8466e6a281289fbe200a3c89618258ec

    #this cmd will only generate patch for commit 9153154c8466e6a281289fbe200a3c89618258ec

    #we can use -o dir to point out the dir where to generate the patch ,like git format-patch -o ./floyd/ -1

    ============== 

    #copy a git depository

    #only need to copy .git under the git depository,and use cmd git reset --hard HEAD

    #then we will see the whole files in hte depository.

    git branch -a
    git checkout -b floyd origin/floyd

    That Is All,maybe add more using skills for git later

    __floyd.peng

     

  • 相关阅读:
    常见26个jquery使用技巧详解(比如禁止右键点击、隐藏文本框文字等)
    禁用页面及页面所有frame内的右键菜单
    JS模态窗口返回值兼容问题解决方案
    winform登录时,在密码框按下回车,直接登陆
    C#中实现邮件发送功能
    CTFHub-彩蛋(持续更新~)
    CTFHub技能树-目录遍历
    免密钥方式登陆配置
    Ansible_Day1
    Python_Day2_共享你的代码
  • 原文地址:https://www.cnblogs.com/rayfloyd/p/2759109.html
Copyright © 2011-2022 走看看