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

     

    安装git

    Linux下安装

    CentOS为例:

    yum install git

    Windwos下安装

    下载地址: https://git-scm.com/downloads

    配置git

    这里以配置全局为例:

    配置user信息

    git config --global user.name "Mike"
    git config --global user.email "Mike_Zhang@live.com"

    配置http代理

    git config --global http.proxy 'socks5://127.0.0.1:1080'
    git config --global https.proxy 'socks5://127.0.0.1:1080'

    取消配置命令:

    git config --global --unset http.proxy
    git config --global --unset https.proxy

    使用git

    初始化

    git init

    添加本地所有文件

    git add *

    递交

    git commit -m "git test init"

    查看日志

    git log

    检验仓库

    git clone user@host:path

    例如:

    git clone root@172.16.16.101:/root/tmp/test1

    添加分支

    语法:

    git checkout -b 分支名字

    例如:

    git checkout -b branch1

    添加branch1分支

    分支递交

    git checkout 分支名称
    git commit -m "注释"

    例如:

    git checkout branch1
    git commit -m "branch1 init"

    返回主分支

    git checkout master

    合并子分支到主分支

    语法如下:

    git merge 子分支名称

    比如:

    git merge branch1

    删除子分支

    git branch -d  子分支名称
    git branch -d branch1

    拉数据

    git pull

    推数据

    git push

    在使用git push 代码到数据仓库时,提示如下错误:

    [remote rejected] master -> master (branch is currently checked out)

    这是由于git默认拒绝了push操作,需要在服务端进行设置,修改.git/config文件后面添加如下代码:

    [receive]
        denyCurrentBranch = ignore 

    放弃单个文件的修改

    git checkout – 文件名
    比如:
    git checkout – test1.txt

    放弃本地所有递交和改动,并将本地主分支指向它

    git fetch origin
    git reset --hard origin/master 

    让 git 输出彩色

    git config --global color.status auto 
    git config --global color.diff auto 
    git config --global color.branch auto 
    git config --global color.interactive auto 

    本文github地址:

    https://github.com/mike-zhang/mikeBlogEssays/blob/master/2012/20120604_git的简单使用.rst

    欢迎补充 

  • E-Mail : Mike_Zhang@live.com
  • 转载请注明出处,谢谢!
查看全文
  • 相关阅读:
    Azure 虚拟机安全加固整理
    AzureARM 使用 powershell 扩容系统磁盘大小
    Azure Linux 云主机使用Root超级用户登录
    Open edX 配置 O365 SMTP
    powershell 根据错误GUID查寻错误详情
    azure 创建redhat镜像帮助
    Azure Powershell blob中指定的vhd创建虚拟机
    Azure Powershell 获取可用镜像 PublisherName,Offer,Skus,Version
    Power BI 连接到 Azure 账单,自动生成报表,可刷新
    Azure powershell 获取 vmSize 可用列表的命令
  • 原文地址:https://www.cnblogs.com/MikeZhang/p/gitSimpleExamples.html
  • Copyright © 2011-2022 走看看