zoukankan      html  css  js  c++  java
  • Git命令拾掇

    修改commit信息

    git commit --amend -m 'The new message'
    

    拉取单个分支代码

    一般用在拉取社区代码某个patch代码查看,可以减少代码拉取量

    git clone https://github.com/lgo/flink.git --single-branch  --branch master --depth 2
    

    --depth 2 指定了只拉最近两个commit

    如果后续又想拉取全量的分支(主要就是修改git config文件)

    git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"
    git fetch origin
    

    应用patch

    从github pull request生成patch:

    E.g., from:
    https://github.com/php/php-src/pull/296
    
    To:
    https://github.com/php/php-src/pull/296.patch
    
    curl https://patch-diff.githubusercontent.com/raw/apache/flink/pull/12345.patch -o 12345.patch
    git apply 12345.patch
    

    使用ssh替换https://

    设置某个仓库

    git remote set-url origin git@github.com:Aitozi/flink.git
    

    全量替换

    git config --global url."git@github.com:".insteadOf http://github.com/ --add
    git config --global url."git@github.com:".insteadOf https://github.com/ --add
    

    将一个commit重新拆分成多个

    git reset commitId
    

    有时候单个commit过大,需要将其拆分开,可以利用git reset命令将本地的提交回退,通常我们回退一个commit的方法是 git reset --hard commitId,这样就会把本地的代码的工作区和commit都进行回退。

    但是修改commit(拆分)的需求一般是要将commit回退,但是工作区(简单的说就是你的文件改动)不回退,然后你再逐批git add 文件,重新添加到index,再重新commit即可,那么使用默认的git reset commitId就是这个行为。

    关于workspace,index,commit的关系 https://stackoverflow.com/questions/3689838/whats-the-difference-between-head-working-tree-and-index-in-git

    撤销文件的修改

    1. 如果没有被git add到索引区
    git checkout file
    
    1. 如果被git add到索引区,但没有做git commit提交
    git reset  HEAD file
    git checkout file
    
    1. 如果已被提交,则需要先回退当前提交到工作区,然后撤销文件a的修改
    git reset  HEAD^
    git checkout file
    

    本文来自博客园,作者:Aitozi,转载请注明原文链接:https://www.cnblogs.com/Aitozi/p/15759720.html

  • 相关阅读:
    常用Git命令清单
    上海金瑢信息有限公司面试
    上海视频面试
    bootstrp-3.0
    B站小姐姐面试分享2
    B站小姐姐分享第一次电话面试
    Array.from()方法就是将一个类数组对象或者可遍历对象转换成一个真正的数组。
    findIndex
    es5,es6
    es6数组去重
  • 原文地址:https://www.cnblogs.com/Aitozi/p/15759720.html
Copyright © 2011-2022 走看看