zoukankan      html  css  js  c++  java
  • git的使用

    yuyue@workplace:~ $ git --version
    git version 2.3.8 (Apple Git-58)

    1. git配置
    git config --global user.name "yuyue"
    git config --global user.email "yuyue@xxxx.163.com"
    注:去掉--global参数是单独为当前项目设置

    2. Create a new repository
    mkdir git-partial-revert
    cd git-partial-revert
    git init
    touch README.md
    git add README.md
    git commit -m "first commit"
    git remote add origin git@xxxxxxxxxxxxxxxxxxxxxx/git-partial-revert.git
    git push -u origin master
    要关联一个远程库,使用命令git remote add origin git@xxxxxxxxxxxxxxxxxxxxxx/git-partial-revert.git;
    远程库的名字就是origin,这是Git默认的叫法,也可以改成别的,但是origin这个名字一看就知道是远程库。
    关联后,使用命令git push -u origin master第一次推送master分支的所有内容;
    此后,每次本地提交后,只要有必要,就可以使用命令git push origin master推送最新修改;

    把本地库的内容推送到远程,用git push命令,实际上是把当前分支master推送到远程。
    由于远程库是空的,我们第一次推送master分支时,加上了-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。


    3. Push an existing Git repository
    cd existing_git_repo
    git remote add origin git@xxxxxxxxxxxxxxxxxxxxxxx/git-partial-revert.git
    git push -u origin master

    4.git修改提交的用户名和Email
    git push 的时候出现这种报错:
    remote: git log 中发现 email@example.com 邮箱非法,请务必使用公司邮箱.

    这个时候需要修改提交的用户名和Email:

    #!/bin/sh -e

    git filter-branch
    --env-filter '
    case "${GIT_AUTHOR_NAME} ${GIT_AUTHOR_EMAIL}" in
    *@163.com*)
    export GIT_AUTHOR_NAME="yuyue"
    export GIT_AUTHOR_EMAIL="yuyue@hello.com"
    ;;
    esac
    case "${GIT_COMMITTER_NAME} ${GIT_COMMITTER_EMAIL}" in
    *@163.com*)
    export GIT_COMMITTER_NAME="yuyue"
    export GIT_COMMITTER_EMAIL="yuyue@hello.com"
    ;;
    esac
    '

    5. 执行 git push 时看到如下消息:
    $ git push
    warning: push.default is unset; its implicit value has changed in
    Git 2.0 from 'matching' to 'simple'. To squelch this message
    and maintain the traditional behavior, use:

    git config --global push.default matching

    To squelch this message and adopt the new behavior now, use:

    git config --global push.default simple

    When push.default is set to 'matching', git will push local branches
    to the remote branches that already exist with the same name.

    Since Git 2.0, Git defaults to the more conservative 'simple'
    behavior, which only pushes the current branch to the corresponding
    remote branch that 'git pull' uses to update the current branch.

    See 'git help config' and search for 'push.default' for further information.
    (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
    'current' instead of 'simple' if you sometimes use older versions of Git)


    不带任何参数的git push,默认只推送当前分支,这叫做simple方式。此外,还有一种matching方式,会推送所有有对应的远程分支的本地分支。
    Git 2.0版本之前,默认采用matching方法,现在改为默认采用simple方式。如果要修改这个设置,可以采用git config命令。

    修改默认设置
    从上述消息提示中的解释,我们可以修改全局配置,使之不会每次 push 的时候都进行提示。对于 matching 输入如下命令即可:
    git config --global push.default matching
    而对于 simple ,请输入:
    git config --global push.default simple


  • 相关阅读:
    document.URL 和 windows.location.href的区别
    毕向东udp学习笔记3多线程聊天
    毕向东udp学习笔记2
    毕向东udp学习笔记1
    udp 服务器界面监听
    android jni 总复习(转载)
    Android jni 编程4(对基本类型二维整型数组的操作)
    Android jni 编程3(对基本类型一维整型数组的操作)总结版
    Android jni 编程2(对基本类型一维整型数组的操作)
    Android jni 编程1(对基本类型字符串的操作)
  • 原文地址:https://www.cnblogs.com/yuyue2014/p/4826036.html
Copyright © 2011-2022 走看看