zoukankan      html  css  js  c++  java
  • Git 入门

    Git 笔记


    PS:就是简单的 Git 笔记

    思维导入

    Git 整体用法

    安装

    这里基于Debian/Ubuntu

    [root@BenLam-vm_0 ~]# sudo apt-add-repository ppa:git-core/ppa
    [root@BenLam-vm_0 ~]# sudo apt-get update
    [root@BenLam-vm_0 ~]# sudo apt-get install git
    

    配置用户名 && 邮箱

    [root@BenLam-vm_0 ~]# git config  --global user.name "用户名"
    [root@BenLam-vm_0 ~]# git config  --global user.emal "邮箱"
    

    验证配置

    [root@BenLam-vm_0 ~]# git config  --list
    user.name = *****
    user.email = *@*.com
    

    该文件保存在 /root/.gitconfig 文件中

    生成插入密钥

    [root@BenLam-vm_0 ~]# ssh-keygen -t rsa -C "自己的邮箱地址"
    Generating public/private rsa key pair.
    Enter file in which to save the key (~/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in ~/.ssh/id_rsa.
    Your public key has been saved in ~/.ssh/id_rsa.pub.
    The key fingerprint is:
    **********************
    

    GItHub 插入密钥

    验证登录

    [root@BenLam-vm_0 ~]# ssh -T *@*.com
    Hi ......! You've successfully authenticated, but Gitlab does not provide shell access.
    

    创建仓库

    [root@BenLam-vm_0 ~]# mkdir ~/test                            # 创建git所有项目仓库目录
    [root@BenLam-vm_0 ~]# cd ~/test                               # 跳转到上一步创建的目录
    [root@BenLam-vm_0 ~]# git init --bare example.git             # 初始化一个example.git的空项目仓库
    [root@BenLam-vm_0 ~]# cd ~/project                            # 跳转的工作目录
    [root@BenLam-vm_0 ~]# git clone ~/test/example.git           # 克隆家目录中的空仓库
    
    # 初始化项目
    [root@BenLam-vm_0 ~]# touch README
    [root@BenLam-vm_0 ~]# git add README 
    [root@BenLam-vm_0 ~]# git commit -m 'Add README, initial project' README
    [root@BenLam-vm_0 ~]# git push origin master
    

    常用命令

    git init                    :当前目录变成git存储目录(在该目录下生成隐藏目录 .git )
    git add "file"              :把当前所有文件放进暂存区
    git commit                  :把暂存区的所有文件提交到仓库,放进当前分支master
    git commit -m "备注"        :添加注释
    git status                  :查看仓库当前状态
    git diff "file"             :查看文件具体修改内容。(diff是difference)
    git log                     :查看提交日志
    git log --pretty==oneline   :查看 commit_ID
    git reflog                  :查看被记录的每次命令(回滚)
    git reset --hard commit_ID  :回到指定版本
    git reset --HEAD^           :回到上一个版本
    git reset --HEAD^ ^         :回到上上个版本
    git reset --HEAD~100        :回到上100个版本
    git chekout -- "备注"       :丢弃工作区的修改
    

    远程命令

    git remote add origin https://***/test.git   :关联git库
    git clone https://***/test                   :克隆git库回本地
    git push -u origin master                    :本地master分支推送远程库 (第一次推送)
    

    分支命令

    git branch test       :创建test分支
    git checkout test     :进入test分支
    git branch            :查看所有分支
    git branch -d test    :删除test分支
    git merge test        :合并test分支到当前分支
    git log --graph       :查看合并分支图
    git stash             :把当前工作现场储藏起来(可通过git stastus看工作区是空的)
    git stash pop         :恢复现场,并删掉stash的内容
    git tag               :查看所有标签
    git tag v1.0          :在当前分支内打标签
    git tag -d v1.0       :删除v1.0标签
    
  • 相关阅读:
    LeetCode 1122. Relative Sort Array (数组的相对排序)
    LeetCode 46. Permutations (全排列)
    LeetCode 47. Permutations II (全排列 II)
    LeetCode 77. Combinations (组合)
    LeetCode 1005. Maximize Sum Of Array After K Negations (K 次取反后最大化的数组和)
    LeetCode 922. Sort Array By Parity II (按奇偶排序数组 II)
    LeetCode 1219. Path with Maximum Gold (黄金矿工)
    LeetCode 1029. Two City Scheduling (两地调度)
    LeetCode 392. Is Subsequence (判断子序列)
    写程序判断系统是大端序还是小端序
  • 原文地址:https://www.cnblogs.com/BenLam/p/12620512.html
Copyright © 2011-2022 走看看