zoukankan      html  css  js  c++  java
  • Git的使用上传与下载github

    下载git

    • 下载git工具是第一步

    Git的使用上传与下载

    创建本地仓库

    • 在选择的文件夹中鼠标右键打开git Bash here ,在命令行输入git init创建该文件夹的本地仓库

    将文件夹文件提交到本地库中

    • 使用git add .将文件夹内容存入本地仓库,然后给本次提交命名git commit -m "first commit"

    image-20201217221312400

    将文件上传到git

    • 找到git远程仓库链接,然后使用git remote add origin +链接 ,最后使用git push -u origin master(第一次有 -u ,之后可无)上传到github

    image-20201218091937242

    image-20201218092121344

    这样就表示成功上传了,若存在无法上传成功的现象(比如需要输入github密码,账号等):此时我们可以采用配置密码账号或者配置ssh来以便下次操作。

    配置账号密码的方式

    git config --global user.name "账户名"  
    git config --global user.email "账户邮箱"
    

    配置ssh的操作

    • 在桌面使用git Bash here
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面
    $ ~/.ssh
    bash: /c/Users/Administrator/.ssh: Is a directory
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面
    $ ssh-keygen -t rsa -C "GitHub账户邮箱"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
    Created directory '/c/Users/Administrator/.ssh'.
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa
    Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub
    The key fingerprint is:
    SHA256:******************************************************
    The key's randomart image is:
    +---[RSA    2]----+
    |   .. o          |
    |.    . oo o      |
    |.+ =.  o.= .     |
    |.   .  .+.o      |
    |   .   oS... .   |
    |    o  a so . o+ |
    |     +o o oo.o=++|
    |           .o+==+|
    |      E.    oo.o+|
    +----[SHA   ]-----+
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面
    $ ssh -T git@github.com
    The authenticity of host 'github.com (*******)' can't be established.
    RSA key fingerprint is SHA256:**************************.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added 'github.com,*******' (RSA) to the list of known hosts.
    Hi easternblood! You've successfully authenticated, but GitHub does not provide shell access.
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面
    
    

    使用git进行版本控制

    添加版本一

    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest (master)
    $ git add .
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest (master)
    $ git commit -m "two commit"
    [master 5f944f8] two commit
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 testtwo.txt
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest (master)
    $ git tag twocommit
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest (master)
    $ git push --tags
    Enumerating objects: 4, done.
    Counting objects: 100% (4/4), done.
    Delta compression using up to 4 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 263 bytes | 263.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
    To https://github.com/easternblood/gittest.git
     * [new tag]         twocommit -> twocommit
    

    添加版本二

    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest (master)
    $ git add .
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest (master)
    $ git commit -m "three commit"
    [master 136a6d5] three commit
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 testthree.txt
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest (master)
    $ git tag threecommit
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest (master)
    $ git push --tags
    Enumerating objects: 3, done.
    Counting objects: 100% (3/3), done.
    Delta compression using up to 4 threads
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (2/2), 265 bytes | 265.00 KiB/s, done.
    Total 2 (delta 0), reused 0 (delta 0), pack-reused 0
    To https://github.com/easternblood/gittest.git
     * [new tag]         threecommit -> threecommit
    

    版本一切换到版本二

    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest ((twocommit))
    $ git checkout threecommit
    Previous HEAD position was 5f944f8 two commit
    HEAD is now at 136a6d5 three commit
    
    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest ((threecommit))
    $ git reset --hard
    HEAD is now at 136a6d5 three commit
    

    其他

    打印所有提交日志

    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest (master)
    $ git log
    commit 136a6d52717532df6aedfede17f8fff92425df18 (HEAD -> master, tag: threecommit)
    Author: easterblood <1780707273@qq.com>
    Date:   Fri Dec 18 13:49:56 2020 +0800
    
        three commit
    
    commit 5f944f8647996d09df11cdb88651ee9e5ace884c (tag: twocommit)
    Author: easterblood <1780707273@qq.com>
    Date:   Fri Dec 18 13:46:50 2020 +0800
    
        two commit
    
    commit e0119fd499390ee96180afa23d0e359283774aca (origin/master)
    Author: easterblood <1780707273@qq.com>
    Date:   Thu Dec 17 22:12:55 2020 +0800
    
        first commit
    

    打印所有版本名称

    Administrator@SD-20190717XGSK MINGW64 /f/新桌面/gittest ((threecommit))
    $ git tag
    threecommit
    twocommit
    
  • 相关阅读:
    CSS盒模型
    js异步加载——defer和async的区别
    href和src的区别
    JS中Null与Undefined的区别
    浅谈Web Workers
    flex布局学习笔记
    Promise
    js数组类型检测
    JavaScript中的遍历
    Autocomplete
  • 原文地址:https://www.cnblogs.com/dongxuelove/p/14154671.html
Copyright © 2011-2022 走看看