日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

86.git使用 建立和克隆远程仓库

發(fā)布時(shí)間:2025/5/22 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 86.git使用 建立和克隆远程仓库 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

22.5/22.6 單機(jī)上使用git

22.7 建立遠(yuǎn)程倉庫

22.8 克隆遠(yuǎn)程倉庫

?

?

?

?

?

22.5/22.6 單機(jī)上使用git

?

?

git是分布式的。所謂分布式是我們不依賴網(wǎng)絡(luò)。你再你電腦上使用git我在我電腦上使用git們都可以,不需要把我的代碼更新到服務(wù)端上去 。在本地做操作就可以了

1.yum install -y git

#yum安裝即可

2.mkdir /data/gitroot

#創(chuàng)建git 目錄

3.cd /data/gitroot

4.git init //初始化倉庫

5.echo -e ?“123\naaa\n456\nbbb” > 1.txt //創(chuàng)建一個(gè)新文件

#隨便寫點(diǎn)東西

6.git add 1.txt //把1.txt添加到倉庫,做標(biāo)記

7.git commit -m “add new file 1.txt” //add完了必須要commit才算真正把文件提交到git倉庫里

#-m""雙引號(hào)里指定解釋說明這個(gè)文件,可盡量寫的清楚

8.再次更改1.txt

9.git status ?//查看當(dāng)前倉庫中的狀態(tài),比如是否有改動(dòng)的文件(未提交的)

10.git diff 1.txt??//可以對(duì)比1.txt本次修改了什么內(nèi)容,相比較倉庫里面的版本

#也就是查看變更

11.git log//查看所有提交記錄。前面的字符是ID號(hào)

#版本回退

#多更改幾次1.txt,然后add,commit,就可查看

12.git log --pretty=oneline//一行顯示。前面的字符是ID號(hào)

#基于git log可顯示的更加好看

13.git reset --hard f7c8e9//回退版本,其中后面跟的字符串是ID號(hào)簡(jiǎn)寫

#撤銷修改

#也可以利用ID號(hào)再回到之前的已經(jīng)回退過的版本,但前提你要知道要回退的那個(gè)ID號(hào)

14.git reflog //查看所有歷史版本

#這個(gè)命令可以查看所有的歷史版本及ID號(hào),包括已經(jīng)刪掉的

15.rm -f 1.txt//不小心刪除了1.txt

git checkout -- 1.txt//恢復(fù)1.txt #注意空格

16.如果1.txt文件修改,add后但沒有commit,再想回退到上一次提交的狀態(tài),可以使用git reset HEAD 1.txt來取消標(biāo)記。#也就是可以將你add命令的標(biāo)記去掉

再執(zhí)行g(shù)it checkout -- 1.txt(就恢復(fù)1.txt到修改之前的狀態(tài))

17.刪除文件

echo -e "11111111111\n2222222222" > 2.txt #測(cè)試

git rm 2.txt #刪除2.txt

git commit -m "rm 2.txt" #提交也就是將庫里的文件刪除

18. git commit -a #可以查看提示信息

?

?

?

實(shí)例:

[root@axinlinux-01 ~]# yum install -y git

[root@axinlinux-01 ~]# mkdir /data/gitroot

[root@axinlinux-01 ~]# cd /data/gitroot/

[root@axinlinux-01 gitroot]# git init

初始化空的 Git 版本庫于 /data/gitroot/.git/

[root@axinlinux-01 gitroot]# ls -la #當(dāng)前目錄下會(huì)生成.git的文件。跟svn很像

總用量 0

drwxr-xr-x 3 root root 18 11月 22 16:58 .

drwxr-xr-x 12 root root 167 11月 22 16:57 ..

drwxr-xr-x 7 root root 119 11月 22 16:58 .git

[root@axinlinux-01 gitroot]# vim 1.txt #隨便寫點(diǎn)東西

[root@axinlinux-01 gitroot]# git add 1.txt #添加到倉庫,做標(biāo)記

[root@axinlinux-01 gitroot]# git commit -m "add 1.txt" #真正提交到倉庫。但是報(bào)錯(cuò)了。意思是讓我們告訴他我們的郵箱以及username。有提示我們?cè)趺床僮?/p>

*** Please tell me who you are.

?

Run

?

git config --global user.email "you@example.com"

git config --global user.name "Your Name"

?

to set your account's default identity.

Omit --global to set the identity only in this repository.

?

fatal: unable to auto-detect email address (got 'root@axinlinux-01.(none)')

[root@axinlinux-01 gitroot]# git config --global user.email "519321158@qq.com" #按操作輸入郵箱

[root@axinlinux-01 gitroot]# git config --global user.name "axin" #按操作輸入username

[root@axinlinux-01 gitroot]# git commit -m "add 1.txt" #再次提交

[master(根提交) 3369881] add 1.txt

1 file changed, 4 insertions(+)

create mode 100644 1.txt

[root@axinlinux-01 gitroot]# git status

# 位于分支 master

無文件要提交,干凈的工作區(qū)

[root@axinlinux-01 gitroot]# vim 1.txt #變更一下,但是不提交

[root@axinlinux-01 gitroot]# git status #我們查看狀態(tài),就會(huì)出現(xiàn)會(huì)提交的。以及怎么提交

# 位于分支 master

# 尚未暫存以備提交的變更:

# (使用 "git add <file>..." 更新要提交的內(nèi)容)

# (使用 "git checkout -- <file>..." 丟棄工作區(qū)的改動(dòng))

#

# 修改: 1.txt

#

修改尚未加入提交(使用 "git add" 和/或 "git commit -a")

[root@axinlinux-01 gitroot]# git diff 1.txt #查看變更

diff --git a/1.txt b/1.txt

index 06b4546..4b2d89e 100644

--- a/1.txt

+++ b/1.txt

@@ -3,4 +3,4 @@ dfnjdshfjhdkjfhsdk

njkndkjfnhkdjsnfkjdsnf

dfdfdf

735678465874368564376587435

-

+43679839885679875698859677

[root@axinlinux-01 gitroot]# git log

commit 9bd505e01e4713b386b01b55faa109465a609762

Author: axin <519321158@qq.com> #我們首次登陸設(shè)置的,可以在配置中查看到

Date: Thu Nov 22 17:20:54 2018 +0800

?

add 1.txt again3

下面還有其他版本,不做演示了

[root@axinlinux-01 gitroot]# cat /root/.gitconfig #是在這定義了你的全局配置

[root@axinlinux-01 gitroot]# git log --pretty=oneline #比起git log更加規(guī)范

9bd505e01e4713b386b01b55faa109465a609762 add 1.txt agent3

3655c5f4cb7f018bb36fe0d75301a223a334fe48 add 1.txt agent2

4e654b08101e8acb95ee09f84f24a6206842835f add 1.txt agent

3369881e206ece9abeab7234bef9c1192789f9b5 add 1.txt

[root@axinlinux-01 gitroot]# git reset --hard 3369881e206ece9abeab72 #后面的數(shù)字可簡(jiǎn)寫幾個(gè)

HEAD 現(xiàn)在位于 3369881 add 1.txt

[root@axinlinux-01 gitroot]# git log --pretty=oneline

3369881e206ece9abeab7234bef9c1192789f9b5 add 1.txt

[root@axinlinux-01 gitroot]# git reflog #查看所有的歷史版本。可以讓我們知道并來回回退各個(gè)歷史版本。前面的是ID號(hào)

9bd505e HEAD@{0}: reset: moving to 9bd505e01e4713b3

3369881 HEAD@{1}: reset: moving to 3369881e206ece9abeab72

9bd505e HEAD@{2}: commit: add 1.txt agent3

3655c5f HEAD@{3}: commit: add 1.txt agent2

4e654b0 HEAD@{4}: commit: add 1.txt agent

3369881 HEAD@{5}: commit (initial): add 1.txt

[root@axinlinux-01 gitroot]# rm -rf 1.txt #假設(shè)我們不小心刪掉了這個(gè)文件

[root@axinlinux-01 gitroot]# ls

[root@axinlinux-01 gitroot]# git checkout -- 1.txt #可以用git checkout -- 1.txt來恢復(fù)。注意空格

[root@axinlinux-01 gitroot]# ls #然后就有了。因?yàn)樗€存在于你的版本管理庫里,雖然目錄里已經(jīng)沒有了

1.txt

[root@axinlinux-01 gitroot]# vim 1.txt

[root@axinlinux-01 gitroot]# git add 1.txt

[root@axinlinux-01 gitroot]# git reset HEAD 1.txt

重置后撤出暫存區(qū)的變更:

M 1.txt

[root@axinlinux-01 gitroot]# git checkout -- 1.txt

17.

[root@axinlinux-01 gitroot]# git rm 1.txt #使用git rm將1.txt刪除

rm '1.txt'

[root@axinlinux-01 gitroot]# git commit -m "delete 1.txt" #再次提交就是講庫里的也刪掉了

[master e0ad56c] delete 1.txt

1 file changed, 6 deletions(-)

delete mode 100644 1.txt

[root@axinlinux-01 gitroot]# ls #就沒有了

[root@axinlinux-01 gitroot]# git checkout -- 1.txt #而且也恢復(fù)不來

error: pathspec '1.txt' did not match any file(s) known to git.

[root@axinlinux-01 gitroot]# git reflog #恢復(fù)的話使用git erflog來查看歷史版本

e0ad56c HEAD@{0}: commit: delete 1.txt

1a3d7c8 HEAD@{1}: commit: add 1.txt agint

9bd505e HEAD@{2}: reset: moving to 9bd505e01e4713b3

3369881 HEAD@{3}: reset: moving to 3369881e206ece9abeab72

9bd505e HEAD@{4}: commit: add 1.txt agent3

3655c5f HEAD@{5}: commit: add 1.txt agent2

4e654b0 HEAD@{6}: commit: add 1.txt agent

3369881 HEAD@{7}: commit (initial): add 1.txt

[root@axinlinux-01 gitroot]# git reset --hard 1a3d7c8 #然后在使用git reset --hard ID號(hào)來恢復(fù)

HEAD 現(xiàn)在位于 1a3d7c8 add 1.txt agint

[root@axinlinux-01 gitroot]# ls

1.txt 2.txt

?

?

?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

?

?

?

?

22.7 建立遠(yuǎn)程倉庫

?

?

?

1.首先到 https://github.com 注冊(cè)一個(gè)賬號(hào),創(chuàng)建自己的git,點(diǎn)repositories 再點(diǎn)new

2.名字自定義,比如叫studygit 選擇public 點(diǎn) create repository

3.添加key:右上角點(diǎn)自己頭像,選擇settings,左側(cè)選擇SSH and GPG keys

4.左側(cè)點(diǎn)New SSH key,把linux機(jī)器上的~/.ssh/id_rsa.pub內(nèi)容粘貼到這里

5.把本地倉庫推送到遠(yuǎn)程倉庫 git remote add origin git@github.com:aminglinux/studygit.git //這一步是在遠(yuǎn)程創(chuàng)建一個(gè)新的倉庫studygit,名字盡量和本地的一致

6.git push -u origin master //然后把本地的studygit倉庫推送到遠(yuǎn)程的studygit

下一次再推送,就可以直接 git push

?

?

?

?

實(shí)例:

進(jìn)入github網(wǎng)站,創(chuàng)建賬號(hào)

輸入username為axin-linux,郵箱為519321158@qq.com,密碼為wx15098751520

再做三次傻逼的游戲,就可以點(diǎn)擊sign in登錄了

?

?

以上,就會(huì)看到這個(gè)界面。想有一些簡(jiǎn)單的用法或說明啥的,一會(huì)在linux上還會(huì)用到這些提示的用法

此時(shí)還需要加一個(gè)秘鑰。目的是為了認(rèn)證,你得告訴他我是一個(gè)合法的用戶

?

?

以上,公鑰的方法為,linux上:

[root@axinlinux-01 gitroot]# ssh-keygen #ssh-keygen命令生成密鑰對(duì)

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa): #回車回車回車即可

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa. #這個(gè)是私鑰,在這里路徑里

Your public key has been saved in /root/.ssh/id_rsa.pub. #帶pub的為公鑰,在這個(gè)路徑里

The key fingerprint is:

SHA256:upAdKxtWB6rI5MaSnlrXbuKz8WQfXohi+NwqQyjAZqQ root@axinlinux-01

The key's randomart image is:

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

| |

| . |

|+ . |

|E+ . . |

|+o . o S |

|Bo.o = * . |

|=*+ @ O o . |

|+.+*o&.+ o |

|oo +B*= o |

+----[SHA256]-----+

[root@axinlinux-01 gitroot]# cd #因?yàn)楣€在root目錄下,直接cd出來

[root@axinlinux-01 ~]# cat .ssh/id_rsa.pub #cat 這個(gè)公鑰文件就可以了

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDXXjoeyXRbpHSwxJa8kvnGev9HV7xqHfQxxVL711ypsMMaKGlpcRVGhRWNkfzS37W0jAfnVZJX3/nSD2BEcrmqmPAxRG48+OZMBhEqh6g6KeCe0JgOA0azm/gpujrrcRNLxbVsT6dTGiRzxfvAG2OPqwOCWN/a3QMPXpdd2IDVTSAw0GMDBYUpr+tHu1DzeVogt5wvdkcBAtb9+caDAAWM0uZLLlG/mZ+Zm2FqX7j8J9LPpy2LIeJF0OBbzeFHMHT1zdUkpLBL5FQSmQ2hrwweT3iqcBXB/A7MNQNan7SFAW4vj7LiUWuxA301RBHuY8e9sS74nLb9lJZds1yle5Hz root@axinlinux-01

?

以上,會(huì)讓你在輸入一次密碼。就會(huì)出現(xiàn)這個(gè)畫面。

接下來還要在客戶端上(linux)上,新建一個(gè)倉庫,然后在這個(gè)倉庫寫一些東西,再把這些東西推送到遠(yuǎn)程上去

[root@axinlinux-01 ~]# cd /tmp/ #就在tmp下創(chuàng)建這個(gè)倉庫吧

[root@axinlinux-01 tmp]# mkdir apelearn #為了與遠(yuǎn)程端保持一致,最好也寫成一樣的名稱

[root@axinlinux-01 tmp]# cd apelearn/ #cd進(jìn)去

[root@axinlinux-01 apelearn]#

到這,有點(diǎn)小問題。我又重新搞了一次

[root@axinlinux-01 tmp]# rm -rf apelearn/

[root@axinlinux-01 tmp]# mkdir aming_linux

[root@axinlinux-01 tmp]# cd aming_linux/

[root@axinlinux-01 aming_linux]# echo "# aming_linux" >> README.md #從這一步開始都是復(fù)制的建遠(yuǎn)程庫(web上)之后提示的操作

[root@axinlinux-01 aming_linux]# git init

初始化空的 Git 版本庫于 /tmp/aming_linux/.git/

[root@axinlinux-01 aming_linux]# git add README.md

[root@axinlinux-01 aming_linux]# git commit -m "first commit"

[master(根提交) 25ca739] first commit

1 file changed, 1 insertion(+)

create mode 100644 README.md

[root@axinlinux-01 aming_linux]# git remote add origin https://github.com/axin-linux/aming_linux.git

[root@axinlinux-01 aming_linux]# git push -u origin master

Username for 'https://github.com': axin-linux #初次登錄會(huì)讓輸入用戶名和密碼,就是一開始創(chuàng)建的用戶名和密碼

Password for 'https://axin-linux@github.com':

Counting objects: 3, done.

Writing objects: 100% (3/3), 216 bytes | 0 bytes/s, done.

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

remote:

remote: Create a pull request for 'master' on GitHub by visiting:

remote: https://github.com/axin-linux/aming_linux/pull/new/master

remote:

To https://github.com/axin-linux/aming_linux.git

* [new branch] master -> master

分支 master 設(shè)置為跟蹤來自 origin 的遠(yuǎn)程分支 master。

以上,就把本地的文件推送到了遠(yuǎn)程。那怎么看遠(yuǎn)程有沒有呢?回到web上,刷新一下界面就能看到我們按照提示建的README了

[root@axinlinux-01 aming_linux]# vim 2.txt #我們?cè)賮頊y(cè)試一下。創(chuàng)建個(gè)2.txt

[root@axinlinux-01 aming_linux]# git add 2.txt

[root@axinlinux-01 aming_linux]# git commit -m "add 2.txt"

[master 27e1249] add 2.txt

1 file changed, 1 insertion(+)

create mode 100644 2.txt

[root@axinlinux-01 aming_linux]# git push #記得要推一下。才能到遠(yuǎn)程

再回到web上刷新一下就有了

?

?

?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

?

?

?

?

22.8 克隆遠(yuǎn)程倉庫

?

?

?

github上有很多開源的項(xiàng)目。實(shí)際工作,使用最多的就是我們?cè)趺窗堰h(yuǎn)程上這些項(xiàng)目搞到本地上來

1.cd /home

2.git clone git@github.com:aminglinux/lanmp.git

#使用git clone后面跟克隆的地址

它提示,會(huì)在當(dāng)前目錄下初始化一個(gè)倉庫,并創(chuàng)建一個(gè).git的目錄,如下

Initialized empty Git repository in /home/lanmp/.

3.git/完成后,ls可以看到一個(gè)lanmp的目錄

4.cd lanmp

5.vi lanmp.sh 編輯一下文件,然后提交

6.git add lanmp.sh

7.git commit -m "sdlfasdf"

8.然后再推送到遠(yuǎn)程服務(wù)端

git push

9.如果我們?cè)谶h(yuǎn)程里(web上)足了一些文件的更改,要拉倒本地:

git pull

?

?

實(shí)例:

[root@axinlinux-01 aming_linux]# git clone git@github.com:aminglinux/lanmp.git

#git clone克隆的地址就是上圖中標(biāo)出的地址

正克隆到 'lanmp'...

Warning: Permanently added the RSA host key for IP address '13.229.188.59' to the list of known hosts.

remote: Enumerating objects: 32, done.

remote: Total 32 (delta 0), reused 0 (delta 0), pack-reused 32

接收對(duì)象中: 100% (32/32), 5.99 KiB | 0 bytes/s, done.

處理 delta 中: 100% (6/6), done.

[root@axinlinux-01 aming_linux]# cd lanmp/

[root@axinlinux-01 lanmp]# ls

lanmp.sh README.md

?

?

?

?

?

轉(zhuǎn)載于:https://my.oschina.net/u/3866149/blog/3030838

總結(jié)

以上是生活随笔為你收集整理的86.git使用 建立和克隆远程仓库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。