zoukankan      html  css  js  c++  java
  • Git一些简单但非常重要并常用的操作命令


    1.将本地与github进行关联配置

    生成公钥

    ssh-keygen -t rsa -C "jiasheng.mei@hpe.com"

    将公钥拷贝到github中

    在公钥同文件夹(.ssh)下创建config文件,文件内容

    Host ssh.github.com
        User git
        Hostname ssh.github.com
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/id_rsa
        Port 443
    

    生成公钥后将公钥配置到github上

    将github上的项目clone到本地

    git clone git@github.com:jiashengp/test.git

    在本地init一个git项目

    git init

    修改了文件后添加

    git add .

    commit并写commit注释

    git commit -m "commit text"

    将本地和github库关联

    git remote add origin git@github.com:jiashengp/test.git

    如果出现fatal: remote origin already exists.则直接进行下面语句

    git push origin master

    给你的队友创建一个分支

    1. git branch cjun
    2. git add .
    3. git commit -m "Create cjun branch give chengjun"

    同步到github上

    1. git push -u origin cjun

    这时你可以在github上看到为队友创建的分支

    查看分支:git branch
    切换分支:git checkout newBranch

    你的队友在github上改了readme.md,你需要同步到本地的git仓库

    将github上cjun分支的下载到临时的分支temp

    1. git fetch origin cjun:temp

    看下同一个文件你和你的队友有啥区别

    1. git diff temp (在那个分支下,就是这个分支和temp比较)

    合并temp分支到本地的master分支(也可以是其他分支)

    1. git merge temp

    把临时分支干掉

    1. git branch -D temp

    其实上面等价:

    git pull origin cjun:temp

    如果是远程分支(cjun)与当前所在分支合并

    git pull origin cjun

    $ git checkout Zhaozheng
    $ vi readme.md
    $ git commit -m "change readme.md use branch zhaozheng"
    $ git checkout master
    $ git merge Zhaozheng
    $ cat readme.md

    从github上更新,本地修改并最终同步到github

    $ cat README.md
    $ git pull origin master
    $ clear
    $ vi README.md
    $ git add .
    $ git commit -m "testgit2 commit third"
    $ git push origin master

  • 相关阅读:
    HDU5171 GTY's birthday gift —— 矩阵快速幂
    UVA10870 Recurrences —— 矩阵快速幂
    HDU4965 Fast Matrix Calculation —— 矩阵乘法、快速幂
    UVA11551 Experienced Endeavour —— 矩阵快速幂
    D6 I
    亲和串
    Kmp 算法模板 C
    Buy the Ticket
    寒假D3 A Find the Lost Sock
    寒假 D3 D Modular Inverse
  • 原文地址:https://www.cnblogs.com/jiashengmei/p/6339624.html
Copyright © 2011-2022 走看看