真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Python全棧開發(fā)之Git

No.1 Git

特點(diǎn)

  • 版本控制:可以解決多人同時(shí)開發(fā)的代碼問題,也可以找回歷史代碼
  • 分布式:Git是一個(gè)分布式版本控制系統(tǒng),同一個(gè)Git倉庫,可以分布到不同的機(jī)器上,首先會有一臺計(jì)算機(jī)充當(dāng)服務(wù)器,這臺計(jì)算機(jī)7*24小時(shí)服務(wù),其他計(jì)算機(jī)都是從這臺計(jì)算機(jī)克隆一份代碼到自己的計(jì)算機(jī)中,并且各自把各自的修改提交到服務(wù)器倉庫里,也可以從服務(wù)器倉庫拉取別人的提交

安裝

sudo apt-get install git -y

No.2 版本創(chuàng)建與回退

使用

創(chuàng)建一個(gè)版本庫

創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、盂縣網(wǎng)絡(luò)推廣、微信小程序定制開發(fā)、盂縣網(wǎng)絡(luò)營銷、盂縣企業(yè)策劃、盂縣品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供盂縣建站搭建服務(wù),24小時(shí)服務(wù)熱線:18980820575,官方網(wǎng)址:www.cdcxhl.com

git init

創(chuàng)建一個(gè)版本

git add test.txt
git commit -m 'v1.0'

查看工作區(qū)狀態(tài)

get status

查看版本記錄

git log
git log --pretty=oneline 將每次提交放到一行顯示
git log --pretty=oneline --graph 以圖形化方式顯示每次提交

版本回退

git reset --hard HEAD^ 其中HEAD表示當(dāng)前最新版本,一個(gè)^表示回退一個(gè)版本,有幾個(gè)^表示回退幾個(gè)版本
git reset --hard HEAD~1 1表示回退一個(gè)版本,那么10就是回退10個(gè)版本
git reset --hard HEAD

查看操作記錄

git reflog

工作區(qū)、暫存區(qū)、版本庫

  • 計(jì)算機(jī)中的目錄就是一個(gè)工作區(qū)
  • 工作區(qū)中有一個(gè)隱藏目錄.git,就是版本庫,版本庫中存在了許多東西,其中最重要的是stage(暫存區(qū)),還有一個(gè)是git為我們自動創(chuàng)建的第一個(gè)分支master,以及指向master的HEAD指針,因此第一個(gè)分支是master,所以當(dāng)我們執(zhí)行g(shù)it commit的時(shí)候是向master分支上推送,git add 文件是將修改后的文件放到暫存區(qū),git commit是將暫存區(qū)中的數(shù)據(jù)提交到工作區(qū)

管理修改

echo 'this is first line' >> test.txt
git add test.txt
echo 'this is first line' >> test.txt
git commit -m 'v1.1'
git status # 發(fā)現(xiàn)第二次修改test.txt文件后,并沒有真正的加入到工作區(qū),所以并沒有提交到版本庫
On branch master
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   test.txt

no changes added to commit (use "git add" and/or "git commit -a")

撤銷修改

撤銷對test.txt文件的修改

get checkout -- test.txt

如果要撤銷暫存區(qū)的修改時(shí)

git reset HEAD test.txt

對比文件

對比工作區(qū)中的test.txt文件和版本庫中的有什么不同

git diff test.txt HEAD -- test.txt

對比兩個(gè)版本中test.txt文件的不同

git diff HEAD HEAD^ -- test.txt

刪除文件

我們將目錄中的test.txt刪除,git知道我們刪除了文件,但是工作區(qū)和版本庫就不知道了,所以我們執(zhí)行g(shù)it status就可以知道哪些文件被刪除了

rm -rf test.txt
git status

現(xiàn)在我們有兩個(gè)選擇,一是確定這個(gè)文件要被刪除,二是確定這個(gè)文件誤刪

# 1.
git rm test.txt
git commit
# 2.
git checkout -- test.txt

No.4 分支管理

創(chuàng)建與合并

git把我們每次提交的版本形成一條時(shí)間線,這個(gè)時(shí)間線就是一個(gè)分支,目前,這個(gè)分支叫master,每次提交后HEAD指向master,master指向提交,每次提交,master都會向前移動一步,所以這條時(shí)間線越來越長,當(dāng)我們創(chuàng)建分支slave后,HEAD指向slave,指向新提交,從此,再次提交就會將版本提交到slave分支,而master不變,當(dāng)我們在salve分支上的工作完成了,就可以合并分支

  • 查看分支 git branch
  • 創(chuàng)建并切換分支 git checkout -b
  • 切換分支 git checkout
  • 合并分支 git merge
  • 刪除分支 git branch -d

解決沖突

合并也不是一帆風(fēng)順的,比如說,我在工作區(qū)中有一個(gè)test.txt文件,這個(gè)文件中沒有任何數(shù)據(jù),我在master分支中向第一行增加了一行數(shù)據(jù),提交到版本庫中,然后切換到slave,在這個(gè)文件中新增加了一行數(shù)據(jù),然后提交到版本庫中,再進(jìn)行合并就會出現(xiàn)沖突

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git checkout -b slave
Switched to a new branch 'slave'

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ cat test.txt
master:the new code

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ vi test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ cat test.txt
master:the new code
slave:the new code

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git add test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git commit -m '1.2'
[slave 5035bfb] 1.2
 1 file changed, 1 insertion(+)

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git checkout master
Switched to branch 'master'

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ cat test.txt
master:the new code

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ vi test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ cat test.txt
master:the new code
master:the new code

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git add test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git commit -m '1.3'
[master e46f9b7] 1.3
 1 file changed, 2 insertions(+)

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git merge slave
Auto-merging test.txt
CONFLICT (content): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.

# 解決沖突
kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master|MERGING)
$ cat test.txt
master:the new code
<<<<<<< HEAD
master:the new code

=======
slave:the new code
>>>>>>> slave

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master|MERGING)
$ vi test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master|MERGING)
$ cat test.txt
master:the new code
slave:the new code

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master|MERGING)
$ git add test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master|MERGING)
$ git commit -m '1.4'
[master b252477] 1.4

分支管理策略

通常,合并分支時(shí),git會盡可能的使用fast forward模式,但是有時(shí)候快速合并沒有成功但是也沒有沖突,這個(gè)時(shí)候會合并之后做一次新的提交

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ vi test1.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ cat test1.txt
add new code

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git add test1.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git commit -m '1.5'
[slave 5fa46e2] 1.5
 1 file changed, 1 insertion(+)
 create mode 100644 test1.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git checkout master
Switched to branch 'master'

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ vi test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ cat test.txt
master:the new code
slave:the new code
master:add new code

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git merge slave
Merge made by the 'recursive' strategy.
 test1.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 test1.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git log --pretty=oneline
bee1e463867f605f16c3fbad6a50ea36f4e0b20a (HEAD -> master) 合并slave分支
5fa46e2ec62346526554b04b62a468afbde0f9ba (slave) 1.5
b2524777899baab52783e1b49360fedc1e6a7e50 1.4
e46f9b7b5c379238ddca5db70746bc4f9f8c5edc 1.3
5035bfba43172b02bdbb7447fd9ebb018e6f49f5 1.2
2ae2bcac4258f41cb1a1e3a3a81a572be80c28f9 1.1
8d3dee945a68e5996d9c088a9769f43fc5c75228 1.0

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git log --pretty=oneline --graph
*   bee1e463867f605f16c3fbad6a50ea36f4e0b20a (HEAD -> master) 合并slave分支
|\
| * 5fa46e2ec62346526554b04b62a468afbde0f9ba (slave) 1.5
* |   b2524777899baab52783e1b49360fedc1e6a7e50 1.4
|\ \
| |/
| * 5035bfba43172b02bdbb7447fd9ebb018e6f49f5 1.2
* | e46f9b7b5c379238ddca5db70746bc4f9f8c5edc 1.3
|/
* 2ae2bcac4258f41cb1a1e3a3a81a572be80c28f9 1.1
* 8d3dee945a68e5996d9c088a9769f43fc5c75228 1.0

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git branch -d slave
Deleted branch slave (was 5fa46e2).

但是快速合并分支后刪除分支會丟失掉分支信息,所以我們很多時(shí)候需要禁用快速合并

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git checkout -b slave
Switched to a new branch 'slave'
M       test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ vi test2.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git add test2.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git commit -m '1.6'
[slave 1e833e6] 1.6
 1 file changed, 2 insertions(+)
 create mode 100644 test2.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git checkout master
Switched to branch 'master'
M       test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git merge --no-ff -m '禁用快速合并' slave
Merge made by the 'recursive' strategy.
 test2.txt | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 test2.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git log --graph --pretty=oneline
*   cabeb0f4edc6617d27e1a7624be927a0f5f7da59 (HEAD -> master) 禁用快速合并
|\
| * 1e833e62109f3dd266883834bf11014d85c4a3dc (slave) 1.6
|/
*   bee1e463867f605f16c3fbad6a50ea36f4e0b20a 合并slave分支
|\
| * 5fa46e2ec62346526554b04b62a468afbde0f9ba 1.5
* |   b2524777899baab52783e1b49360fedc1e6a7e50 1.4
|\ \
| |/
| * 5035bfba43172b02bdbb7447fd9ebb018e6f49f5 1.2
* | e46f9b7b5c379238ddca5db70746bc4f9f8c5edc 1.3
|/
* 2ae2bcac4258f41cb1a1e3a3a81a572be80c28f9 1.1
* 8d3dee945a68e5996d9c088a9769f43fc5c75228 1.0

bug分支

軟件開發(fā)中,出現(xiàn)bug是經(jīng)常性的事情,在git中,每個(gè)bug可以通過一個(gè)臨時(shí)分支來修復(fù),修復(fù)后刪除分支,假如突然出現(xiàn)一個(gè)bug就需要立即修復(fù),但是該分支的工作還沒有完成,沒有完成就沒辦法進(jìn)行提交,所以就用到了git中的保存現(xiàn)場功能(stash)

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   test.txt

no changes added to commit (use "git add" and/or "git commit -a")

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git stash
Saved working directory and index state WIP on master: cabeb0f 禁用快速合并

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git status
On branch master
nothing to commit, working tree clean

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git checkout slave
Switched to branch 'slave'

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git checkout -b bug001
Switched to a new branch 'bug001'

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (bug001)
$ vi test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (bug001)
$ git add test.txt

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (bug001)
$ git commit -m 'bug001修復(fù)完成'
[bug001 aab106b] bug001修復(fù)完成
 1 file changed, 1 deletion(-)

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (bug001)
$ git checkout slave
Switched to branch 'master'

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git merge bug001
Merge made by the 'recursive' strategy.
 test.txt | 1 -
 1 file changed, 1 deletion(-)

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git branch -d bug001
Deleted branch bug001 (was aab106b).

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (slave)
$ git checkout master
Switched to branch 'master'

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git stash list
stash@{0}: WIP on master: cabeb0f 禁用快速合并

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git stash pop
gOn branch slave
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   test.txt

no changes added to commit (use "git add" and/or "git commit -a")
Dropped refs/stash@{0} (8fe9c203f75afc7929433faabc52e02a6d555ff4)

kernel@DESKTOP-67P59AO MINGW64 /d/Codes/Git/test (master)
$ git status
On branch slave
Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        modified:   test.txt

no changes added to commit (use "git add" and/or "git commit -a")

No.5 使用GitHub

添加ssh賬戶

如果某臺機(jī)器需要與GitHub進(jìn)行交互,那么就要把這臺機(jī)器的ssh公鑰添加到GitHub賬戶上

  1. 編輯.github文件,使用ssh-keygen -t rsa -C "郵箱地址",生成ssh密鑰

  2. 點(diǎn)擊賬戶頭像后的下拉三角,選擇settings,選擇SSH and GPG keys選項(xiàng),單擊New SSH keys,復(fù)制id_rsa.pub文件里的內(nèi)容,點(diǎn)擊Add SSH key

克隆項(xiàng)目

git clone 項(xiàng)目地址

上傳分支

git push origin 分支名稱

跟蹤遠(yuǎn)程分支

git branch --set-upstream-to=origin/slave master

當(dāng)本地成功跟蹤遠(yuǎn)程分支后,當(dāng)修改代碼后,只需要git push就可以將修改提交到遠(yuǎn)程

從遠(yuǎn)程分支拉取代碼

git pull origin 分支名稱


文章名稱:Python全棧開發(fā)之Git
當(dāng)前網(wǎng)址:http://weahome.cn/article/pjdjso.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部