欧美free性护士vide0shd,老熟女,一区二区三区,久久久久夜夜夜精品国产,久久久久久综合网天天,欧美成人护士h版

首頁綜合 正文
目錄

柚子快報激活碼778899分享:GitHub入門與實踐

柚子快報激活碼778899分享:GitHub入門與實踐

http://yzkb.51969.com/

1.GitHub入門與實踐

參考資料:《GitHub入門與實踐》

聲明:本篇博客內(nèi)容由筆者跟隨該書進(jìn)行實際操作并記錄過程而來,該篇博客內(nèi)容大部分來自上述提到的書中。

GitHub入門與實踐

1.GitHub入門與實踐1.1 對本地計算機里安裝的 Git 進(jìn)行設(shè)置1.2 使用github的前期準(zhǔn)備1.2.1 創(chuàng)建賬戶設(shè)置基本信息1.2.2 設(shè)置SSH Key1.2.2 在github帳號內(nèi)添加公鑰

1.3 創(chuàng)建倉庫1.4 公開代碼1.4.1 git clone (將github遠(yuǎn)程倉庫克隆到本地)1.4.2 coding (本地編寫代碼)1.4.3 git status (查看倉庫狀態(tài))1.4.4 git add (添加到暫存區(qū)) / git commit(保存?zhèn)}庫歷史記錄) / git log(查看提交日志)1.4.5 git push (代碼推送回github遠(yuǎn)程倉庫)

1.5 基本操作1.5.1 git init (初始化倉庫)1.5.2 git status(查看倉庫的狀態(tài))1.5.3 git add(向暫存區(qū)中添加文件)1.5.4 git commit(保存?zhèn)}庫的歷史記錄)1.5.5 git log(查看提交日志)1.5.6 git diff(查看更改前后的差別)

1.6 分支操作1.6.1 git branch(顯示分支一覽表)1.6.2 git checkout -b(創(chuàng)建、切換分支)1.6.3 git merge(合并分支)1.6.4 git log --graph(以圖表形式查看分支)

1.7 更改提交的操作1.7.1 git reset(回溯歷史版本)1.7.2 git commit --amend(修改提交信息)1.7.3 git rebase -i(壓縮歷史)

1.8 推送至遠(yuǎn)程倉庫1.8.1 git remote add(添加遠(yuǎn)程倉庫)1.8.2 git push(推送至遠(yuǎn)程倉庫)

1.9 從遠(yuǎn)程倉庫獲取1.9.1 git clone(獲取遠(yuǎn)程倉庫)1.9.2 git pull (獲取最新的遠(yuǎn)程倉庫分支)

1.10 嘗試Pull Request1.11 接收Pull Request

下圖改編自in/viciloria

1.1 對本地計算機里安裝的 Git 進(jìn)行設(shè)置

首先來設(shè)置使用 Git 時的姓名和郵箱地址

$ git config --global user.name "Firstname Lastname"

$ git config --global user.email "your_email@example.com"

1.2 使用github的前期準(zhǔn)備

1.2.1 創(chuàng)建賬戶設(shè)置基本信息

1.2.2 設(shè)置SSH Key

GitHub 上連接已有倉庫時的認(rèn)證,是通過使用了 SSH 的公開密鑰認(rèn)證方式進(jìn)行的?,F(xiàn)在讓我們來創(chuàng)建公開密鑰認(rèn)證所需的 SSH Key,并將其添加至 GitHub

運行下面的命令創(chuàng)建 SSH Key

$ ssh-keygen -t rsa -C "your_email@example.com"

Generating public/private rsa key pair.

Enter file in which to save the key

(/Users/your_user_directory/.ssh/id_rsa): 按回車鍵

Enter passphrase (empty for no passphrase): 輸入密碼

Enter same passphrase again: 再次輸入密碼

輸入密碼后會出現(xiàn)以下結(jié)果

Your identification has been saved in /Users/your_user_directory/.ssh/id_rsa.

Your public key has been saved in /Users/your_user_directory/.ssh/id_rsa.pub.

The key fingerprint is:

fingerprint值 your_email@example.com

The key's randomart image is:

+--[ RSA 2048]----+

|.++|

|= o O .|

id_rsa 文件是私有密鑰,id_rsa.pub 是公開密鑰 在 GitHub 中添加公開密鑰,今后使用私鑰進(jìn)行認(rèn)證

1.2.2 在github帳號內(nèi)添加公鑰

Title自己取名字,Key type用默認(rèn),Key添加之前生成的公鑰 使用以下命令查看公鑰,并將該公鑰添加到上圖中Key的位置

$ cat ~/.ssh/id_rsa.pub

ssh-rsa 公開密鑰的內(nèi)容 your_email@example.com

用手中的私人密鑰與 GitHub 進(jìn)行認(rèn)證和通信 輸入命令

ssh -T git@github.com

Enter passphrase for key '~/.ssh/id_rsa': [輸入自己github密碼]

Hi,aaa.You've successfully authenticated,but github does not provide shell access.

1.3 創(chuàng)建倉庫

右上角創(chuàng)建新倉庫 README.md

一般在這個文件中標(biāo)明本倉庫所包含 (1) 軟件的概要 (2) 使用流程 (3) 許可協(xié)議 等信息

.gitignore文件的作用

.gitignore 文件通過指定忽略規(guī)則,幫助開發(fā)者管理項目中不必要提交的文件,優(yōu)化項目的存儲和協(xié)作效率,同時防止敏感信息的意外泄露。

常見許可協(xié)議

1.4 公開代碼

嘗試在已有倉庫中添加代碼并加以公開 剛剛創(chuàng)建的倉庫的頁面

1.4.1 git clone (將github遠(yuǎn)程倉庫克隆到本地)

首先將已有倉庫 clone 到本地的開發(fā)環(huán)境中

$ git clone git@github.com:irvingwu5/hello_world.git

Cloning into 'hello_world'...

Enter passphrase for key '/home/.../.ssh/id_rsa': [輸入github密碼]

remote: Enumerating objects: 3, done.

remote: Counting objects: 100% (3/3), done.

remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 (from 0)

Receiving objects: 100% (3/3), done.

cd hello_world/

ls

README.md

1.4.2 coding (本地編寫代碼)

這里我們編寫一個 hello.cpp 文件

1.4.3 git status (查看倉庫狀態(tài))

由于 hello.cpp 還沒有添加至 Git 倉庫,所以顯示為 Untracked files

$ git status

On branch main

Your branch is up to date with 'origin/main'.

Untracked files:

(use "git add ..." to include in what will be committed)

hello.cpp

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

1.4.4 git add (添加到暫存區(qū)) / git commit(保存?zhèn)}庫歷史記錄) / git log(查看提交日志)

通過 git add命令將文件加入暫存區(qū) A,再通過 git commit命令提交。添加成功后,可以通過 git log命令查看提交日志 將 hello.cpp 提交 (commit) 至倉庫。這樣一來,這個文件就進(jìn)入了版本管理系統(tǒng)的管理之下。今后的更改管理都交由 Git 進(jìn)行

$ git add hello.cpp

$ git commit -m "Add hello script by cpp"

[main 5f4b9e4] Add hello script by cpp

1 file changed, 28 insertions(+)

create mode 100644 hello.cpp

$ git log

commit ........ (HEAD -> main)

Author: Wu Irving <....@....com>

Date: Fri Oct 4 16:35:20 2024 +0800

Add hello script by cpp

commit ........ (origin/main, origin/HEAD)

Author: Wu Xiang Yu <124986252+irvingwu5@users.noreply.github.com>

Date: Fri Oct 4 16:12:46 2024 +0800

Initial commit

1.4.5 git push (代碼推送回github遠(yuǎn)程倉庫)

$ git push

Enter passphrase for key '/home/.../.ssh/id_rsa': [輸入github密碼]

Enumerating objects: 4, done.

Counting objects: 100% (4/4), done.

Delta compression using up to 16 threads

Compressing objects: 100% (3/3), done.

Writing objects: 100% (3/3), 718 bytes | 718.00 KiB/s, done.

Total 3 (delta 0), reused 0 (delta 0), pack-reused 0

To github.com:irvingwu5/hello_world.git

f68e6e2..5f4b9e4 main -> main

1.5 基本操作

1.5.1 git init (初始化倉庫)

要使用 Git 進(jìn)行版本管理,必須先初始化倉庫。Git 是使用 git init命令進(jìn)行初始化的。請實際建立一個目錄并初始化倉庫

本地終端輸入命令,創(chuàng)建空目錄,進(jìn)入目錄,進(jìn)行初始化操作

$ mkdir git-tutorial

$ cd git-tutorial/

$ git init

hint: Using 'master' as the name for the initial branch. This default branch name

hint: is subject to change. To configure the initial branch name to use in all

hint: of your new repositories, which will suppress this warning, call:

hint:

hint: git config --global init.defaultBranch

hint:

hint: Names commonly chosen instead of 'master' are 'main', 'trunk' and

hint: 'development'. The just-created branch can be renamed via this command:

hint:

hint: git branch -m

Initialized empty Git repository in /home/.../Documents/CppProjects/git-tutorial/.git/

git init 是一個 Git 命令,用于初始化一個新的 Git 倉庫。它的作用主要包括:

1.創(chuàng)建版本控制環(huán)境:git init 命令會在當(dāng)前目錄下創(chuàng)建一個新的 .git 子目錄,這個子目錄包含了 Git 版本控制所需的所有文件和結(jié)構(gòu)。 2.開始跟蹤文件:通過執(zhí)行 git init,你可以開始將當(dāng)前目錄中的文件納入版本控制。這意味著你可以使用其他 Git 命令(如 git add 和 git commit)來跟蹤和管理文件的更改。 3.準(zhǔn)備項目進(jìn)行協(xié)作:如果你計劃將這個項目與他人共享或?qū)⑵渫扑偷竭h(yuǎn)程倉庫(如 GitHub),那么 git init 是第一步。

在 Git 中,我們將這個目錄(.git)的內(nèi)容稱為“附屬于該倉庫的工作樹”。 文件的編輯等操作在工作樹中進(jìn)行,然后記錄到倉庫中,以此管理文件的歷史快照。 如果想將文件恢復(fù)到原先的狀態(tài),可以從倉庫中調(diào)取之前的快照,在工作樹中打開。開發(fā)者可以通過這種方式獲取以往的文件。

.git下各個目錄和文件的含義

1.5.2 git status(查看倉庫的狀態(tài))

工作樹和倉庫在被操作的過程中,狀態(tài)會不斷發(fā)生變化。在 Git 操作過程中時常用 git status命令查看當(dāng)前狀態(tài)

工作樹與 .git 目錄的關(guān)系 工作樹:你直接操作和編輯的文件。這些文件可以是源代碼、文檔、圖像等,屬于項目的實際內(nèi)容。 .git 目錄:用于存儲與版本控制相關(guān)的元數(shù)據(jù)和對象。它管理版本歷史、索引、配置和其他版本控制信息。

工作樹示意圖:

$ git status

On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

on branch master表明我們當(dāng)前正處在master分支下 提交(Commit),是指“記錄工作樹中所有文件的當(dāng)前狀態(tài)”?!癗o commits yet” 尚沒有可提交的內(nèi)容,就是說當(dāng)前我們建立的這個倉庫中還沒有記錄任何文件的任何狀態(tài)。 這里,我們建立 README.md 文件作為管理對象,為第一次提交做前期準(zhǔn)備

$ touch README.md

$ git status

On branch master

No commits yet

Untracked files:

(use "git add ..." to include in what will be committed)

README.md

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

1.5.3 git add(向暫存區(qū)中添加文件)

如果只是用 Git 倉庫的工作樹創(chuàng)建了文件 (touch README.md),那么該文件并不會被記入 Git 倉庫的版本管理對象當(dāng)中。因此我們用 git status命令查看README.md 文件時,它會顯示在 Untracked files 里

要想讓文件成為 Git 倉庫的管理對象,就需要用 git add命令將其加入暫存區(qū)(Stage 或者 Index)中。暫存區(qū)是提交之前的一個臨時區(qū)域

$ git add README.md

$ git status

On branch master

No commits yet

Changes to be committed:

(use "git rm --cached ..." to unstage)

new file: README.md

將 README.md 文件加入暫存區(qū)后,git status命令的顯示結(jié)果發(fā)生了變化。 可以看到,README.md 文件顯示在 Changes to be committed 中了

1.5.4 git commit(保存?zhèn)}庫的歷史記錄)

git commit命令可以將當(dāng)前暫存區(qū)中的文件實際保存到倉庫的歷史記錄中。通過這些記錄,我們就可以在工作樹中復(fù)原文件。

記述一行提交信息

$ git commit -m "First Commit" #加-m參數(shù),則輸入一行提交信息

[master (root-commit) db370d2] First Commit

1 file changed, 0 insertions(+), 0 deletions(-)

create mode 100644 README.md

提交信息示意圖:(當(dāng)倉庫被push到github上才能在頁面看到) 記述詳細(xì)提交信息

$ touch hello.cpp

$ git add hello.cpp

$ git status

On branch master

Changes to be committed:

(use "git restore --staged ..." to unstage)

new file: hello.cpp

$ git commit #不加-m參數(shù),則輸入詳細(xì)提交信息

# Please enter the commit message for your changes. Lines starting (第一行)

# with '#' will be ignored, and an empty message aborts the commit.

#(空行)

# On branch master(第三行以后)

# Changes to be committed: (可以查看本次提交中包含的文件)

# new file: hello.cpp

no add anything

第一行:用一行文字簡述提交的更改內(nèi)容 第二行:空行 第三行以后:記述更改的原因和詳細(xì)內(nèi)容

查看當(dāng)前狀態(tài)

$ git status

On branch master

nothing to commit, working tree clean

當(dāng)前工作樹處于剛剛完成提交的最新狀態(tài),所以結(jié)果顯示沒有更改

1.5.5 git log(查看提交日志)

git log命令可以查看以往倉庫中提交的日志。包括可以查看什么人在什么時候進(jìn)行了提交或合并,以及操作前后有怎樣的差別。

來看看剛才的 git commit命令是否被記錄了

$ git log

commit 1cbd40573990df40f6e7f55bcc58a5c182917d67 (HEAD -> master)

Author: Wu Irving <...@....com>

Date: Fri Oct 4 18:14:40 2024 +0800

no add anything

commit db370d29535422a4a44630ee0a8af9f52ee3569b #指向這個提交的哈希值,Git的其他命令中,在指向提交時會用到這個哈希值

Author: Wu Irving <...@.....com>

Date: Fri Oct 4 17:59:57 2024 +0800

First Commit

只顯示提交信息的第一行 如果只想讓程序顯示第一行簡述信息,可以在 git log命令后加上 --pretty=short。這樣一來開發(fā)人員就能夠更輕松地把握多個提交

$ git log --pretty=short

commit 1cbd40573990df40f6e7f55bcc58a5c182917d67 (HEAD -> master)

Author: Wu Irving <....@.....com>

no add anything

commit db370d29535422a4a44630ee0a8af9f52ee3569b

Author: Wu Irving <....@.....com>

First Commit

只顯示指定目錄、文件的日志 只要在 git log命令后加上目錄名,便會只顯示該目錄下的日志 如果加的是文件名,就會只顯示與該文件相關(guān)的日志

$ git log README.md

commit db370d29535422a4a44630ee0a8af9f52ee3569b

Author: Wu Irving <....@.....com>

Date: Fri Oct 4 17:59:57 2024 +0800

First Commit

顯示文件的改動 如果想查看提交所帶來的改動,可以加上 - p參數(shù),文件的前后差別就會顯示在提交信息之后

$ git log -p

commit 1cbd40573990df40f6e7f55bcc58a5c182917d67 (HEAD -> master)

Author: Wu Irving <....@.....com>

Date: Fri Oct 4 18:14:40 2024 +0800

no add anything

diff --git a/hello.cpp b/hello.cpp

new file mode 100644

index 0000000..e69de29

commit db370d29535422a4a44630ee0a8af9f52ee3569b

Author: Wu Irving <....@.....com>

Date: Fri Oct 4 17:59:57 2024 +0800

First Commit

diff --git a/README.md b/README.md

new file mode 100644

index 0000000..e69de29

只查看 README.md 文件的提交日志以及提交前后的差別

$ git log -p README.md

commit db370d29535422a4a44630ee0a8af9f52ee3569b

Author: Wu Irving <....@.....com>

Date: Fri Oct 4 17:59:57 2024 +0800

First Commit

diff --git a/README.md b/README.md

new file mode 100644

index 0000000..e69de29

1.5.6 git diff(查看更改前后的差別)

git diff命令可以查看工作樹、暫存區(qū)、最新提交之間的差別。

在README.md文件中添加文字,查看更改前后差別 查看工作樹和暫存區(qū)的差別

$ git diff

diff --git a/README.md b/README.md

index e69de29..6e35e14 100644

--- a/README.md

+++ b/README.md

@@ -0,0 +1 @@

+#git tutorial #“+”號標(biāo)出的是新添加的行,被刪除的行則用“-”號標(biāo)出

由于我們尚未用 git add命令向暫存區(qū)添加任何東西,所以程序只會顯示工作樹與最新提交狀態(tài)之間的差別

用 git add命令將 README.md 文件加入暫存區(qū)

$ git add README.md

如果現(xiàn)在執(zhí)行 git diff命令,由于工作樹和暫存區(qū)的狀態(tài)并無差別,結(jié)果什么都不會顯示 要查看與最新提交的差別使用命令 git diff HEAD

$ git diff HEAD

diff --git a/README.md b/README.md

index e69de29..6e35e14 100644

--- a/README.md

+++ b/README.md

@@ -0,0 +1 @@

+#git tutorial

習(xí)慣養(yǎng)成:在執(zhí)行 git commit命令之前先執(zhí)行g(shù)it diff HEAD命令,查看本次提交與上次提交之間有什么差別,等確認(rèn)完畢后再進(jìn)行提交。(這里的 HEAD 是指向當(dāng)前分支中最新一次提交的指針)

使用git commit將剛剛修改過的文件保存到倉庫的歷史記錄中

$ git commit -m "Add function"

[master d16037b] Add function

1 file changed, 1 insertion(+)

查看日志,確認(rèn)是否提交成功

$ git log

commit d16037ba205b79554d772ce8bed20c7b13731760 (HEAD -> master)

Author: Wu Irving <....@.....com>

Date: Fri Oct 4 18:47:02 2024 +0800

Add function

commit 1cbd40573990df40f6e7f55bcc58a5c182917d67

Author: Wu Irving <....@.....com>

Date: Fri Oct 4 18:14:40 2024 +0800

no add anything

commit db370d29535422a4a44630ee0a8af9f52ee3569b

Author: Wu Irving <....@.....com>

Date: Fri Oct 4 17:59:57 2024 +0800

First Commit

1.6 分支操作

1.6.1 git branch(顯示分支一覽表)

git branch命令可以將分支名列表顯示,同時可以確認(rèn)當(dāng)前所在分支

$ git branch

* master #星號表示當(dāng)前所在分支

1.6.2 git checkout -b(創(chuàng)建、切換分支)

$ git checkout -b feature-A #創(chuàng)建并切換分支

Switched to a new branch 'feature-A'

等價于

$ git branch feature-A #創(chuàng)建分支

$ git checkout feature-A #切換分支

查看分支情況

$ git branch

* feature-A

master

feature-A 分支左側(cè)標(biāo)有“*”,表示當(dāng)前分支為 feature-A。在這個狀態(tài)下像正常開發(fā)那樣修改代碼、執(zhí)行 git add命令并進(jìn)行提交的話,代碼就 會提交至 feature-A 分支。 像這樣不斷對一個分支(例如feature-A)進(jìn)行提交的操作,我們稱為 “培育分支” 在README.md中添加一行后進(jìn)行提交

$ nano README.md

#git tutorial

-feature-A

$ git add README.md

$ git commit -m "Add feature-A"

[feature-A bd15091] Add feature-A

1 file changed, 1 insertion(+)

README.md中這一行內(nèi)容添加到了feature-A分支中了

現(xiàn)在我們再來看一看 master 分支有沒有受到影響。首先切換至master 分支,然后查看 README.md 文件,會發(fā)現(xiàn) README.md 文件仍然保持原先的狀態(tài),并沒有被添加文字。feature-A 分支的更改不會影響到master 分支,這正是在開發(fā)中創(chuàng)建分支的優(yōu)點。只要創(chuàng)建多個分支,可以在不互相影響的情況下同時進(jìn)行多個功能的開發(fā)。

$ git checkout master

Switched to branch 'master'

$ nano README.md

#git tutorial

feature-A分支中README.md內(nèi)容

#git tutorial

-feature-A

master分支中README.md內(nèi)容

#git tutorial

切換回上一個分支 用“-”(連字符)代替分支名,就可以切換至上一個分支

$ git checkout -

Switched to branch 'feature-A'

主干分支、特性分支

1.6.3 git merge(合并分支)

假設(shè) feature-A 已經(jīng)實現(xiàn)完畢,想要將它合并到主干分支 master 中。首先切換到 master 分支

$ git branch

* feature-A

master

$ git checkout master

Switched to branch 'master'

$ git branch

feature-A

* master

合并 feature-A 分支。為了在歷史記錄中明確記錄下本次分支合并,我們需要創(chuàng)建合并提交。因此,在合并時加上 --no-ff參數(shù)

$ git merge --no-ff feature-A

# 隨后編輯器會啟動,用于錄入合并提交的信息

Merge branch 'feature-A'

# Please enter a commit message to explain why this merge is necessary,

# especially if it merges an updated upstream into a topic branch.

#

# Lines starting with '#' will be ignored, and an empty message aborts

# the commit.

# 默認(rèn)信息中已經(jīng)包含了是從 feature-A 分支合并過來的相關(guān)內(nèi)容,所以可不必做任何更改。將編輯器中顯示的內(nèi)容保存,關(guān)閉編輯器,然后就會看到下面的結(jié)果。

Merge made by the 'ort' strategy.

README.md | 1 +

1 file changed, 1 insertion(+)

1.6.4 git log --graph(以圖表形式查看分支)

用 git log --graph命令進(jìn)行查看的話,能很清楚地看到特性分支(feature-A)提交的內(nèi)容已被合并。除此以外,特性分支的創(chuàng)建以及合并也都清楚明了

$ git log --graph

* commit 1515c54edfd7ddfaba476e67c0b52bf878c3af78 (HEAD -> master)

|\ Merge: d16037b bd15091

| | Author: Wu Irving <....@.....com>

| | Date: Fri Oct 4 19:48:23 2024 +0800

| |

| | Merge branch 'feature-A'

| |

| * commit bd15091d17ef71bf63e98e9e501d4b66ba43fe67 (feature-A)

|/ Author: Wu Irving <....@.....com>

| Date: Fri Oct 4 19:17:40 2024 +0800

|

| Add feature-A

|

* commit d16037ba205b79554d772ce8bed20c7b13731760

| Author: Wu Irving <....@.....com>

| Date: Fri Oct 4 18:47:02 2024 +0800

|

| Add function

|

* commit 1cbd40573990df40f6e7f55bcc58a5c182917d67

| Author: Wu Irving <....@.....com>

| Date: Fri Oct 4 18:14:40 2024 +0800

|

....

....

1.7 更改提交的操作

1.7.1 git reset(回溯歷史版本)

回溯歷史 要讓倉庫的 HEAD、暫存區(qū)、當(dāng)前工作樹回溯到指定狀態(tài),需要用到 git reset --hard命令。只要提供目標(biāo)時間點的哈希值 A,就可以完全恢復(fù)至該時間點的狀態(tài)

$ git log --graph

* commit 1515c54edfd7ddfaba476e67c0b52bf878c3af78 (HEAD -> master)

|\ Merge: d16037b bd15091

| | Author: Wu Irving <....@.....com>

| | Date: Fri Oct 4 19:48:23 2024 +0800

| |

| | Merge branch 'feature-A'

| |

| * commit bd15091d17ef71bf63e98e9e501d4b66ba43fe67 (feature-A)

|/ Author: Wu Irving <....@.....com>

| Date: Fri Oct 4 19:17:40 2024 +0800

|

| Add feature-A

|

* commit d16037ba205b79554d772ce8bed20c7b13731760

| Author: Wu Irving <....@.....com>

| Date: Fri Oct 4 18:47:02 2024 +0800

|

| Add function

|

* commit 1cbd40573990df40f6e7f55bcc58a5c182917d67

| Author: Wu Irving <....@.....com>

| Date: Fri Oct 4 18:14:40 2024 +0800

|

....

....

回溯到特性分支(feature-A)創(chuàng)建之前的狀態(tài)

$ git reset --hard 1515c54edfd7ddfaba476e67c0b52bf878c3af78

HEAD is now at bd15091 Add feature-A

$ git log --graph

* commit bd15091d17ef71bf63e98e9e501d4b66ba43fe67 (HEAD -> master)

| Author: Wu Irving <....@.....com>

| Date: Fri Oct 4 19:17:40 2024 +0800

|

| Add feature-A

|

* commit d16037ba205b79554d772ce8bed20c7b13731760

| Author: Wu Irving <....@.....com>

| Date: Fri Oct 4 18:47:02 2024 +0800

|

| Add function

|

* commit 1cbd40573990df40f6e7f55bcc58a5c182917d67

| Author: Wu Irving <....@.....com>

| Date: Fri Oct 4 18:14:40 2024 +0800

|

| no add anything

|

* commit db370d29535422a4a44630ee0a8af9f52ee3569b

Author: Wu Irving <....@.....com>

Date: Fri Oct 4 17:59:57 2024 +0800

First Commit

1.7.2 git commit --amend(修改提交信息)

要修改上一條提交信息,可以使用 git commit --amend命令

$ git commit --amend

1.7.3 git rebase -i(壓縮歷史)

git rebase -i(交互式 rebase)中的“壓縮歷史”指的是將多個提交合并為一個或多個提交,從而精簡和整理 Git 提交歷史。這對于清理開發(fā)過程中頻繁的小提交、合并重復(fù)的提交、或者讓項目的提交歷史更為清晰整潔非常有用。

假設(shè)你有以下的提交歷史:

commit 789def4 (HEAD -> feature)

Author: You

Date: Fri Oct 1 2024

Fix typo in README

commit 456abc7

Author: You

Date: Fri Oct 1 2024

Improve README format

commit 123abc1

Author: You

Date: Fri Oct 1 2024

Add initial README

現(xiàn)在,你希望將這些三個提交壓縮成一個提交,整理成一個單一的提交來描述你對 README 文件的所有修改。這時可以使用 git rebase -i。 步驟一:運行 git rebase -i 命令,指定需要進(jìn)行壓縮的范圍。例如,你想將最后三次提交合并,可以運行:

git rebase -i HEAD~3

步驟二:執(zhí)行命令后,Git 會打開一個文本編輯器,顯示類似如下的界面:

pick 123abc1 Add initial README

pick 456abc7 Improve README format

pick 789def4 Fix typo in README

其中,每個 pick 表示一個提交。默認(rèn)情況下,Git 會按歷史順序保留這些提交。

步驟三:為了將這些提交壓縮為一個,你可以將第二和第三個 pick 修改為 squash 或 s,像這樣:

pick 123abc1 Add initial README # pick:保留提交。

squash 456abc7 Improve README format # squash:將該提交的更改壓縮(合并)到前一個提交中。

squash 789def4 Fix typo in README

步驟四:保存并退出編輯器后,Git 會合并這些提交,并打開另一個編輯器,讓你修改新的提交信息。你可以選擇保留各個提交的原始消息,或者編寫一個新的提交消息。比如:

Add initial README and improvements

- Add initial README

- Improve README format

- Fix typo in README

步驟五:保存提交消息后,Git 會完成壓縮操作。最終,提交歷史會變成如下所示:

commit 9abcdef (HEAD -> feature)

Author: You

Date: Fri Oct 1 2024

Add initial README and improvements

經(jīng)過 git rebase -i 壓縮后,原來的三個提交被合并為一個提交,整個歷史變得更加簡潔,提交信息更具代表性,避免了過于細(xì)碎的提交。

1.8 推送至遠(yuǎn)程倉庫

1.8.1 git remote add(添加遠(yuǎn)程倉庫)

在 GitHub 上創(chuàng)建的倉庫路徑為“git@github.com :用戶名/git-tutorial.git”?,F(xiàn)在我們用 git remote add命令將它設(shè)置成本地倉庫的遠(yuǎn)程倉庫

$ git remote add origin git@github.com:github-book/git-tutorial.git

按照上述格式執(zhí)行g(shù)it remote add命令之后,Git 會自動將git@github.com:github-book/git-tutorial.git遠(yuǎn)程倉庫的名稱設(shè)置為 origin(標(biāo)識符)

1.8.2 git push(推送至遠(yuǎn)程倉庫)

推送到master分支 如果想將當(dāng)前分支下本地倉庫中的內(nèi)容推送給遠(yuǎn)程倉庫,需要用到git push命令?,F(xiàn)在假定我們在 master 分支下進(jìn)行操作。

$ git push -u origin master

Counting objects: 20, done.

Delta compression using up to 8 threads.

Compressing objects: 100% (10/10), done.

Writing objects: 100% (20/20), 1.60 KiB, done.

Total 20 (delta 3), reused 0 (delta 0)

To git@github.com:github-book/git-tutorial.git

* [new branch]

master -> master

Branch master set up to track remote branch master from origin.

像這樣執(zhí)行 git push命令,當(dāng)前分支的內(nèi)容就會被推送給遠(yuǎn)程倉庫origin 的 master 分支 推送到master以外的分支 除了 master 分支之外,遠(yuǎn)程倉庫也可以創(chuàng)建其他分支。舉個例子,我們在本地倉庫中創(chuàng)建 feature-D 分支,并將它以同名形式 push 至遠(yuǎn)程倉庫

$ git checkout -b feature-D

Switched to a new branch 'feature-D'

我們在本地倉庫中創(chuàng)建了 feature-D 分支,現(xiàn)在將它 push 給遠(yuǎn)程倉庫并保持分支名稱不變

$ git push -u origin feature-D

Total 0 (delta 0), reused 0 (delta 0)

To git@github.com:github-book/git-tutorial.git

* [new branch]

feature-D -> feature-D

Branch feature-D set up to track remote branch feature-D from origin.

現(xiàn)在,在遠(yuǎn)程倉庫的 GitHub 頁面就可以查看到 feature-D 分支了

1.9 從遠(yuǎn)程倉庫獲取

1.9.1 git clone(獲取遠(yuǎn)程倉庫)

獲取遠(yuǎn)程倉庫

$ git clone git@github.com:github-book/git-tutorial.git

Cloning into 'git-tutorial'...

remote: Counting objects: 20, done.

remote: Compressing objects: 100% (7/7), done.

remote: Total 20 (delta 3), reused 20 (delta 3)

Receiving objects: 100% (20/20), done.

Resolving deltas: 100% (3/3), done.

$ cd git-tutorial

執(zhí)行 git clone命令后我們會默認(rèn)處于 master 分支下,同時系統(tǒng)會自動將 origin 設(shè)置成該遠(yuǎn)程倉庫的標(biāo)識符。也就是說,當(dāng)前本地倉庫的 master 分支與 GitHub 端遠(yuǎn)程倉庫(origin)的 master 分支在內(nèi)容上是完全相同的

$ git branch -a

* master #本地倉庫

remotes/origin/HEAD -> origin/master #遠(yuǎn)程倉庫

remotes/origin/feature-D

remotes/origin/master

我們用 git branch -a命令查看當(dāng)前分支的相關(guān)信息。添加 -a參數(shù)可以同時顯示本地倉庫和遠(yuǎn)程倉庫的分支信息。結(jié)果中顯示了 remotes/origin/feature-D,證明我們的遠(yuǎn)程倉庫中已經(jīng)有了 feature-D 分支

獲取遠(yuǎn)程的 feature-D 分支

$ git checkout -b feature-D origin/feature-D #- b 參數(shù)的后面是本地倉庫中新建分支的名稱 緊接著為遠(yuǎn)程倉庫分支名稱

Branch feature-D set up to track remote branch feature-D from origin.

Switched to a new branch 'feature-D'

修改后將本地的 feature-D 分支提交更改 先執(zhí)行 git add命令,再執(zhí)行 git commit命令 等價于 git commit -am “提交信息”

$ git commit -am "Add feature-D"

[feature-D ed9721e] Add feature-D

1 file changed, 1 insertion(+)

推送 feature-D 分支

$ git push

Counting objects: 5, done.

Delta compression using up to 8 threads.

Compressing objects: 100% (2/2), done.

Writing objects: 100% (3/3), 281 bytes, done.

Total 3 (delta 1), reused 0 (delta 0)

To git@github.com:github-book/git-tutorial.git

ca0f98b..ed9721e feature-D -> feature-D

從遠(yuǎn)程倉庫獲取 feature-D 分支,在本地倉庫中提交更改,再將feature-D 分支推送回遠(yuǎn)程倉庫,通過這一系列操作,就可以與其他開發(fā)者相互合作,共同培育 feature-D 分支,實現(xiàn)某些功能

1.9.2 git pull (獲取最新的遠(yuǎn)程倉庫分支)

遠(yuǎn)程倉庫的 feature-D 分支中更新了內(nèi)容,將本地的 feature-D 分支更新到最新狀態(tài)

$ git pull origin feature-D

remote: Counting objects: 5, done.

remote: Compressing objects: 100% (1/1), done.

remote: Total 3 (delta 1), reused 3 (delta 1)

Unpacking objects: 100% (3/3), done.

From github.com:github-book/git-tutorial

* branch

feature-D -> FETCH_HEAD

First, rewinding head to replay your work on top of it...

Fast-forwarded feature-D to ed9721e686f8c588e55ec6b8071b669f411486b8.

1.10 嘗試Pull Request

Pull Request 是自己修改源代碼后,請求對方倉庫采納該修改時采取的一種行為 現(xiàn)在假設(shè)我們在使用 GitHub 上的一款開源軟件。在使用這款軟件的過程中,我們偶然間發(fā)現(xiàn)了 BUG。為了繼續(xù)使用軟件,我們手動修復(fù)了這個 BUG。如果我們修改的這段代碼能被該軟件的開發(fā)倉庫采納,今后與我們同樣使用這款軟件的人就不會再遇到這個 BUG。為此,我們要第一時間發(fā)送 Pull Request 在 GitHub 上發(fā)送 Pull Request 后,接收方的倉庫會創(chuàng)建一個附帶源代碼的 Issue,我們在這個 Issue 中記錄詳細(xì)內(nèi)容。這就是 Pull Request.Pull Request 在網(wǎng)絡(luò)上也常常被簡稱為 PR

發(fā)送過去的 Pull Request 是否被采納,要由接收方倉庫的管理者進(jìn)行判斷。一般只要代碼沒有問題,對方都會采納。如果有問題,我們會收到評論。只要 Pull Request 被順利采納,我們就會成為這個項目的 Contributor(貢獻(xiàn)者),我們編寫的這段代碼也將被全世界的人使用

不進(jìn)行 Fork 直接從分支發(fā)送 Pull Request 一般說來,在 GitHub 上修改對方的代碼時,需要先將倉庫 Fork 到本地,然后再修改代碼,發(fā)送 Pull Request。但是,如果用戶對該倉庫有編輯權(quán)限,則可以直接創(chuàng)建分支,從分支發(fā)送 Pull Request。利用這一設(shè)計,團(tuán)隊開發(fā)時不妨為每一名成員賦予編輯權(quán)限,免去 Fork 倉庫的麻煩。這樣,成員在有需要時就可以創(chuàng)建自己的分支,然后直接向 master分支等發(fā)送 Pull Request

倉庫的維護(hù)

1.11 接收Pull Request

柚子快報激活碼778899分享:GitHub入門與實踐

http://yzkb.51969.com/

相關(guān)閱讀

評論可見,查看隱藏內(nèi)容

本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。

轉(zhuǎn)載請注明,如有侵權(quán),聯(lián)系刪除。

本文鏈接:http://gantiao.com.cn/post/19537638.html

發(fā)布評論

您暫未設(shè)置收款碼

請在主題配置——文章設(shè)置里上傳

掃描二維碼手機訪問

文章目錄