【git及GitHub使用总结】(一)

GitHub使用总结

(1) 仓库 (Repository) 仓库是用来存放项目代码,每一项目对应一个仓库。

(2) 收藏 (Star) 收藏别人的仓库,方便自己查找。

(3) 复制/克隆项目 (Fork)。
别人仓库的代码可以克隆到自己的账号下的中,可以对仓库进行更改。自己在仓库中对bug进行更改不会影响原作者的仓库,但可以通过向原作者发起请求 (Pull Request)。Fork也可以理解为分叉。

(4) 关注(Watch)
使用Watch功能关注了其他作者的仓库,如果作者的仓库发生更新,会发送通知到自己的账户上(类似于关注了别人就可以关注别人的动态)。

(5) 事物卡片(Issue)
发现别人的仓库代码出现Bug或有疑问时,可以通过Issue来和代码的作者进行咨询和讨论。然后作者可以收到别人的提问,然后可以回复。回复完成可以关闭当前的Issue。

git的使用流程

什么是git?

Git(读音为/gɪt/)是一个开源的[分布式]版本控制系统,可以有效、高速地处理从很小到非常大的项目版本管理。

(1) 工作区(Working Directory) 添加、编辑、修改文件等操作。

(2) 暂存区(Stage) 暂存已修改的文件,最后会统一提交到Git仓库中。

(3) Git仓库(Git Repository) 最终确定的文件保存到Git仓库成为一个新版本。

Git工作流程

Git工作流程有:

(1) 在工作目录中添加、修改、删除文件;
(2) 将需要进行版本管理的文件放入暂存区
(3)将暂存区的文件提交到Git仓库中;

Git管理的文件三种状态对应Git工作流程:

(1) 已修改(modified)
(2) 已暂存(staged)
(3) 已提交(committed)

常用命令

初始化仓库命令

git init

新建文件命令

touch README.md

添加到缓存区的命令、

git add README.md

添加到仓库的命令

git commit -m “提交README.md文件”

推到GitHub的命令

git branch -M main

git remote add origin https://github.com/FeiPF2020/chapter1.git

git push -u origin main //可以替换为SSH

下拉到本地的命令

git pull

git status

cat README.md

例程演示

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git --help
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [--super-prefix=<path>] [--config-env=<name>=<envvar>]
           <command> [<args>]

These are common Git commands used in various situations:

start a working area (see also: git help tutorial)
   clone             Clone a repository into a new directory
   init              Create an empty Git repository or reinitialize an existing one

work on the current change (see also: git help everyday)
   add               Add file contents to the index
   mv                Move or rename a file, a directory, or a symlink
   restore           Restore working tree files
   rm                Remove files from the working tree and from the index
   sparse-checkout   Initialize and modify the sparse-checkout

examine the history and state (see also: git help revisions)
   bisect            Use binary search to find the commit that introduced a bug
   diff              Show changes between commits, commit and working tree, etc
   grep              Print lines matching a pattern
   log               Show commit logs
   show              Show various types of objects
   status            Show the working tree status

grow, mark and tweak your common history
   branch            List, create, or delete branches
   commit            Record changes to the repository
   merge             Join two or more development histories together
   rebase            Reapply commits on top of another base tip
   reset             Reset current HEAD to the specified state
   switch            Switch branches
   tag               Create, list, delete or verify a tag object signed with GPG

collaborate (see also: git help workflows)
   fetch             Download objects and refs from another repository
   pull              Fetch from and integrate with another repository or a local branch
   push              Update remote refs along with associated objects

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
See 'git help git' for an overview of the system.

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ touch wpf.cpp

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git status
On branch center
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        d
        wpf.cpp

nothing added to commit but untracked files present (use "git add" to track)

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ vim wpf.cpp

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ cat wpf.cpp
#include<iostream>
using namespace std;
int main(){
        int a = 1;
        int b = 2;
        cout<<a+b<<endl;
        return 0;
}

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git add wpf.cpp
warning: LF will be replaced by CRLF in wpf.cpp.
The file will have its original line endings in your working directory

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git status
On branch center
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   wpf.cpp

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        d


小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git commit -m "提交wpf.cpp文件"
[center 28b3816] 提交wpf.cpp文件
 1 file changed, 8 insertions(+)
 create mode 100644 wpf.cpp

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git status
On branch center
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        d

nothing added to commit but untracked files present (use "git add" to track)

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git log
commit 28b38166b64c8f170c5610897ee121c23cfd58ff (HEAD -> center)
Author: FeiPF2020 <wpfn218925@163.com>
Date:   Sat May 14 17:11:28 2022 +0800

    提交wpf.cpp文件

commit ad19af6d975f036e3f2a8547502977bc00ba4209
Author: FeiPF2020 <wpfn218925@163.com>
Date:   Sat May 14 17:01:59 2022 +0800

    ‘提交文件’

commit fa4626e4e03eee391e618321cf27d85ffa35095f (master)
Author: wpf <pfwangin2020@outlook.com>
Date:   Thu Sep 9 06:56:16 2021 +0800

    add style.css

commit 3b59a44ff6390ef905c23206c4b4fb97d7de1e8e
Author: wpf <pfwangin2020@outlook.com>
Date:   Wed Sep 8 01:41:01 2021 +0800

    add modified index.html add a head.

commit 00a1703d0f807918dc056ac20fa6a386a029f6a2
Author: wpf <pfwangin2020@outlook.com>
Date:   Wed Sep 8 01:36:22 2021 +0800

    add index.html

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git log --pretty=oneline
28b38166b64c8f170c5610897ee121c23cfd58ff (HEAD -> center) 提交wpf.cpp文件
ad19af6d975f036e3f2a8547502977bc00ba4209 ‘提交文件’
fa4626e4e03eee391e618321cf27d85ffa35095f (master) add style.css
3b59a44ff6390ef905c23206c4b4fb97d7de1e8e add modified index.html add a head.
00a1703d0f807918dc056ac20fa6a386a029f6a2 add index.html

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git log --oneline
28b3816 (HEAD -> center) 提交wpf.cpp文件
ad19af6 ‘提交文件’
fa4626e (master) add style.css
3b59a44 add modified index.html add a head.
00a1703 add index.html

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ gitreflog
bash: gitreflog: command not found

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git reflog
28b3816 (HEAD -> center) HEAD@{0}: commit: 提交wpf.cpp文件
ad19af6 HEAD@{1}: commit: ‘提交文件’
fa4626e (master) HEAD@{2}: checkout: moving from master to center
fa4626e (master) HEAD@{3}: checkout: moving from 3b59a44ff6390ef905c23206c4b4fb97d7de1e8e to master
3b59a44 HEAD@{4}: checkout: moving from master to 3b59a44ff6390ef905c23206c4b4fb97d7de1e8e
fa4626e (master) HEAD@{5}: commit: add style.css
3b59a44 HEAD@{6}: commit: add modified index.html add a head.
00a1703 HEAD@{7}: commit (initial): add index.html

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (center)
$ git branch -M main

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (main)
$ git remote add origin https://github.com/FeiPF2020/chapter1.git

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (main)
$ git push -u origin main
Enumerating objects: 16, done.
Counting objects: 100% (16/16), done.
Delta compression using up to 16 threads
Compressing objects: 100% (13/13), done.
Writing objects: 100% (16/16), 1.72 KiB | 879.00 KiB/s, done.
Total 16 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (3/3), done.
To https://github.com/FeiPF2020/chapter1.git
 * [new branch]      main -> main
Branch 'main' set up to track remote branch 'main' from 'origin'.

小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (main)
$ git pull origin master
fatal: unable to access 'https://github.com/FeiPF2020/chapter1.git/': OpenSSL SSL_read: Connection was reset, errno 10054


小城独困@LAPTOP-KDFLLFJE MINGW64 /g/git使用 (main)
$ git pull
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 651 bytes | 130.00 KiB/s, done.
From https://github.com/FeiPF2020/chapter1
   28b3816..2fb70fb  main       -> origin/main
Updating 28b3816..2fb70fb
Fast-forward
 hh.c | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 hh.c

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值