當前位置:首頁 » 操作系統 » linux配置git

linux配置git

發布時間: 2022-05-21 16:34:06

❶ 如何在linux搭建git遠程版本庫

服務端配置
1、安裝git

2、新建一個用戶,只能用來上傳代碼,而不能通過ssh登錄,比如git用戶
adser git
chsh -s $(command -v git-shell) git
使用git-shell替換bash ,這樣git用戶就不能通過ssh登錄
這一步會有警告,提示git-shell不在shell列表裡,不用擔心。

3、添加ssh公鑰,在/home/git/.ssh/authorized_keys里添加客戶端的公鑰,一行一個。
如果沒有文件,可以新建
mkdir /home/git/.ssh
touch /home/git/.ssh/authorized_keys

客戶端生成公鑰的方法是 ssh-keygen,
windows的在C:\Users\用戶名\.ssh\ 目錄下,打開id_rsa.pub

4、初始化一個空的git倉庫
cd /var
git init --bare sample.git
chown -R git:git sample.git
這一步是讓目錄可以被git用戶修改,否則會出現「permission denied」錯誤。

客戶端
1、可以git clone了
git clone git@伺服器:/var/sample.git 即伺服器上的文件路徑
或者ssh,建議ssh,方便設置埠號
git clone ssh://git@伺服器:埠號/var/sample.git

❷ 如何在 Linux 上安裝 git 服務

安裝Optware IPKG。這個在QNAP官方的App Center里有提供,直接去安裝即可。
安裝Git。這里通過ipkg安裝的Git比較新。官方App Center里提供的git版本比較老。通過SSH登陸admin賬號後運行如下命令。
ipkg update
ipkg install git
初始化git伺服器端倉庫。你的git倉庫務必存放在非系統自帶的目錄下,否則系統重啟之後數據會被抹掉(我嘗試了是這樣的)。假定伺服器端git倉庫目錄為:/opt/repos,項目目錄為hets.git。通過SSH登陸admin賬號後運行如下命令。

❸ 如何搭建linux git伺服器

首先我們分別在Git伺服器和客戶機中安裝Git服務程序(剛剛實驗安裝過就不用安裝了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, proct-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package git-1.8.3.1-4.el7.x86_64 already installed and latest version
Nothing to do

然後創建Git版本倉庫,一般規范的方式要以.git為後綴:
[root@linuxprobe ~]# mkdir linuxprobe.git

修改Git版本倉庫的所有者與所有組:
[root@linuxprobe ~]# chown -Rf git:git linuxprobe.git/

初始化Git版本倉庫:
[root@linuxprobe ~]# cd linuxprobe.git/
[root@linuxprobe linuxprobe.git]# git --bare init
Initialized empty Git repository in /root/linuxprobe.git/

其實此時你的Git伺服器就已經部署好了,但用戶還不能向你推送數據,也不能克隆你的Git版本倉庫,因為我們要在伺服器上開放至少一種支持Git的協議,比如HTTP/HTTPS/SSH等,現在用的最多的就是HTTPS和SSH,我們切換至Git客戶機來生成SSH密鑰:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+

將客戶機的公鑰傳遞給Git伺服器:
[root@linuxprobe ~]# ssh--id 192.168.10.10
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.10'"
and check to make sure that only the key(s) you wanted were added.

此時就已經可以從Git伺服器中克隆版本倉庫了(此時目錄內沒有文件是正常的):
[root@linuxprobe ~]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
warning: You appear to have cloned an empty repository.
[root@linuxprobe ~]# cd linuxprobe
[root@linuxprobe linuxprobe]#

初始化下Git工作環境:
[root@linuxprobe ~]# git config --global user.name "Liu Chuan"
[root@linuxprobe ~]# git config --global user.email "[email protected]"
[root@linuxprobe ~]# git config --global core.editor vim

向Git版本倉庫中提交一個新文件:
[root@linuxprobe linuxprobe]# echo "I successfully cloned the Git repository" > readme.txt
[root@linuxprobe linuxprobe]# git add readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: readme.txt
#
[root@linuxprobe linuxprobe]# git commit -m "Clone the Git repository"
[master (root-commit) c3961c9] Clone the Git repository
Committer: root
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
nothing to commit, working directory clean

但是這次的操作還是只將文件提交到了本地的Git版本倉庫,並沒有推送到遠程Git伺服器,所以我們來定義下遠程的Git伺服器吧:
[root@linuxprobe linuxprobe]# git remote add server [email protected]:/root/linuxprobe.git

將文件提交到遠程Git伺服器吧:
[root@linuxprobe linuxprobe]# git push -u server master
Counting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/root/linuxprobe.git
* [new branch] master -> master
Branch master set up to track remote branch master from server.

為了驗證真的是推送到了遠程的Git服務,你可以換個目錄再克隆一份版本倉庫(雖然在工作中毫無意義):
[root@linuxprobe linuxprobe]# cd ../Desktop
[root@linuxprobe Desktop]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@linuxprobe Desktop]# cd linuxprobe/
[root@linuxprobe linuxprobe]# cat readme.txt
I successfully cloned the Git repository

這篇是詳細介紹Git的,中間有一部分是怎麼去搭建,你可以看下

❹ 如何在Linux下使用Git

Git是一款開源分布式版本控制系統,能夠幫助Linux管理內核開發,那麼Linux要如何使用Git,下面就是Linux使用Git的方法:

  • *初始化git倉庫,使用git init命令

    *添加文件到git倉庫分兩步:

1、使用git add filename ;可分多次使用,添加多個文件到暫存區

2、使用git commit -m 「說明」 ;完成提交到分支

*查看工作區狀態,使用git status 命令;如果提示有修改可使用git diff filename 查看修改內容

*HEAD指向當前版本,HEAD^表示上一個版本,HEAD^^上上一個版本……HEAD~100指向之前第100個版本。

*回退版本:使用git log查看提交歷史;使用git log --pretty=oneline 精簡顯示

使用git reset --hard commit_id 回退到版本號為commit_id的版本

*回退版本之後如果想再看改回來,可以使用git reflog 查看歷史命令,找出想改回的版本號,再使用git reset hard commit_id 返回即可。

*注意:git跟蹤並管理的是修改,而不是文件,如果一個文件修改並add之後,再次修改,如果不再次add就提交的話,只會提交第一次的修改。

  • *撤銷修改:

1、如果文件還在工作區,即沒有add也沒有commit,則使用git checkout -- filename 還原到伺服器版即可;

2、如果已經add到暫存區,首先使用git reset HEAD filename從暫存區取回工作區,再按照1進行操作即可;

3、如果已經提交到版本庫,則按照版本回退的方式進行修改即可;

4、如果已經push到遠程倉庫,就麻煩了

*刪除使用以下命令:

1、git rm filename 從工作區刪除

2、git commit -m 」說明「 更新分支中文件進行刪除

將在工作區的文件刪除之後,可以使用git checkout -- filename 從分支中取回,但是只能恢復文件到最新版本,最後一次提交之後的修改則不能恢復。

  • *分支:

1、創建分支

git checkout -b branchname 創建並切換到改分區,相當於一下兩個命令:

git branch branchname 創建分支

git checkout branchname 切換到分區

2、查看當前指向的分支:git branch 會列出所有分支,當前指向的分支之前多了個*

3、切換分支就是git checkout branchname

4、合並分支:git merge branchname 合並branchname到當前分支

5、刪除分支:git branch -d branchname 刪除branchname分支

注意:創建、合並、刪除分支都非常快,git鼓勵使用分支完成某個任務,合並後刪除分支,和直接在master分支上進行工作是一樣的效果,但是過程更加安全; 這些之所以快是因為在這些過程中我們只是修改了指向分支的指針,如創建一個branch就是創建了一個指向分支的指針,然後修改HEAD指向該指針;即HEAD指向分支,分支就是提交。

  • *沖突解決:

    git無法自動合並分支時,就必須首先解決沖突;解決沖突之後,再提交,即完成了合並

使用git log --graph 可以查看分支合並圖。

*保存工作現場 git stash 保存之後就可以進行其他工作 而不影響上次的修改

恢復工作現場:

1、git stash apply 恢復時並不刪除stash中內容

2、git stash pop 恢復時會刪除stash中的內容

*遠程庫信息產看使用git remote (-v)加上-v顯示信息更加詳細

*分支推送到遠程庫:即將所有本地的提交推送到遠程庫

git push origin(遠程庫名) master (要推送的分支)

*抓取分支:git pull ; git clone

  • *協作模式:

1、使用git push origin branchname 推送自己的修改

2、如果推送失敗,因為遠程分支比本地更新,先使用git pull 合並

3、如果合並有沖突,解決沖突,在本地提交

4、再推送

注意:如果使用git pull 合並時提示 」no tracking information「說明本地分支沒有和遠程分支建立鏈接關系,使用以下指令建立關系:git branch --set -upstream branch origin/branchname

*在本地創建與遠程對應的分支:git branch -b branchname origin/branchname 本地與遠程分支的名稱最好一致

  • *創建標簽

1、打標簽git tag name 默認標簽打在最新提交的commit上,如果想打在其他版本上,找到commit_id即可

2、顯示標簽:git log -pretty=oneline --abbrev -commit

git tag tag_name commit_id

3、查看標簽:git tag 顯示所有標簽

4、查看標簽信息:git show tag_name

5、創建帶有說明的標簽: git tag -a tag_name -m 」信息「;-a表示標簽名,-m指定說明文字

*操作標簽:git tag -d tag_name 刪除標簽

推送標簽到遠程庫:git push origin tag_name

一次推送所有標簽到遠程庫:git push origin --tag

上面就是Linux使用Git的方法了。

❺ 怎樣在linux 上搭建git +apache伺服器

1:伺服器端創建用戶(git)
# sudo adsergit
2:客戶端生成公鑰,並
創建公鑰:ssh-keygen,
在客戶端的用戶目錄下查看生成的公鑰和私鑰對
#cd ~/.ssh
#ls
id_dsa id_dsa.pub

公鑰所在的目錄:windows在」C:/User/username/.ssh」目錄下,linux在」~/.ssh」,~代表用戶目錄
3:伺服器git用戶下添加各個用戶公鑰,並配置ssh服務
將各個用戶的公鑰文件追加在伺服器git用戶的authorized_keys文件中
$ cat id_rsa.john.pub >> ~/.ssh/authorized_keys
$ cat id_rsa.josie.pub >> ~/.ssh/authorized_keys
$ cat id_rsa.jessica.pub >> ~/.ssh/authorized_keys
修改.ssh和authorized_keys的許可權).忘記下面的話,會每次輸入密碼,(ps,被這個坑了好久)
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

4,在git用戶下創建git庫
cd gitDIR
mkdir project.git
cd project.git
git init –bare
5,客戶端使用
提交自己的庫
mkdir project
cd project
git init
vi first.txt
git remote add origin gitserver/gitDIR/project.git
git push origin master
克隆:git clonegit@gitserver/gitDIR/project.git
6,限制開發者登陸
默認情況下,能夠連接git伺服器用戶也可以通過ssh直接登陸伺服器,那麼伺服器將會存在被多用戶登入的風險,限制的方法是:
Vi /etc/passwd

git:x:1000:1000::/home/git:/bin/sh

該行修改後的樣子如下:
git:x:1000:1000::/home/git:/bin/git-shell

❻ linux如何搭建git

1、環境准備
伺服器:CentOS 7.3 + git (1.8.3.1)
客戶端:win10 + git (2.17.0.windows.1)
2、伺服器安裝git
yum install -y git
3、創建git用戶,管理 git服務
[root@localhost home]# useradd git
[root@localhost home]# passwd git
4、伺服器創建git 倉庫
設置/home/git/repository-git 為git 伺服器倉庫,然後把 git 倉庫的 owner 修改為 git 用戶。
復制代碼
[root@localhost git]# mkdir repository-git
[root@localhost git]# git init --bare repository-git/
Initialized empty Git repository in /home/git/repository-gt/
[root@localhost git]# chown -R git:git repository-git/
5、客戶端安裝git
下載 Git for Windows,地址:https://git-for-windows.github.io/
安裝完之後,可以使用 Git Bash 作為命令行客戶端。
5.1、選擇一個目錄 F:\project\sell 作為本地倉庫,右鍵進入Git Bash 命令行模式
初始化本地倉庫:git init
5.2、嘗試克隆一個伺服器的空倉庫到本地倉庫
git clone [email protected]:/home/git/repository-gt
第一次連接到目標 Git 伺服器時會得到一個提示:
The authenticity of host '192.168.116.129(192.168.116.129)' can't be established.
RSA key fingerprint is SHA256:Ve6WV/.
Are you sure you want to continue connecting (yes/no)?
選擇 yes:
Warning: Permanently added '192.168.116.129' (RSA) to the list of known hosts.
此時 C:\Users\用戶名\.ssh 下會多出一個文件 known_hosts,以後在這台電腦上再次連接目標 Git 伺服器時不會再提示上面的語句。

❼ 怎麼在Linux下安裝配置Git服務

1、yum方式安裝
# yum -y install git
如果提示系統提示沒有找到git包,可以採用下面的方式
2、下載Git源碼
官網:http://git-scm.com/
$ tar -xjvf git-1.7.4.1.tar.bz2
$ cd git-1.7.4.1/
$ make prefix=/usr/local all
$ make prefix=/usr/local install
關於更多Linux的學習,請查閱書籍《linux就該這么學》。

❽ Linux下怎麼完成Git的配置

使用git 自從git-1.5.4 , 'git-xyz' 這種用法就不提倡了,而推薦 'git xyz' 風格。 git 的後續版本中將在 make install 時不再安裝 'git-xyz' 這些 hardlinks 。 當如果執行 git --exec-path 輸出的目錄中依然有 git-xyz 這些腳本,你還是可以把這個路徑加到 PATH 環境變數中, 這樣還能夠使用 git-xyz 形式的腳本。 config ------ 我的一些簡單的配置: $ git-config user.name "Jike Song" $ git-config user.email [email][email protected][/email] $ git-config core.editor vim $ git-config core.pager "less -N" $ git-config color.diff true // 顯示 diff 時色彩高亮 $ git-config alias.co checkout // 給 git checkout 取個別名,這樣只輸入 git co 即可 $ git-config sendemail.smtpserver /usr/bin/msmtp 注意,這會在當前 repository 目錄下的 .git/config 中寫入配置信息。 如果 git-config 加了 --global 選項,配置信息就會寫入到 ~/.gitconfig 文件中。 因為你可能用不同的身份參與不同的項目,而多個 項目都用 git 管理,所以建議不用 --global 配置。 $ git-val -l // 列出 git 變數 init ---- $ git-init-db // 創建一個 .git/ 目錄,初始化一個空的 git 倉庫 //這個目錄在git-clone時也會創建。也就是說clone時會自動初始化git //倉庫里需要的東西 clone ----- $ git-clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git [dir name] [dir name] 是你想讓這個倉庫叫什麼名字。 如果不指定,就會等同於目標倉庫的名字。 注意,這種 git server 形式的 repository ,都有一個 filename.git 文件; 而對於 *.git 的操作,也可以 針對.git 所在的目錄: $ mkdir tmp/ $ cd tmp/ $ git-clone ~/Sources/linux-2.6 或者通過 ssh : $ git-clone [email][email protected][/email]:/home/arc/Sources/linux-2.6 此時當前目錄下有一個 .git/ 目錄 . 以下我們都在 linux-2.6/ 下演示: 使用git 自從git-1.5.4 , 'git-xyz' 這種用法就不提倡了,而推薦 'git xyz' 風格。 git 的後續版本中將在 make install 時不再安裝 'git-xyz' 這些 hardlinks 。 當如果執行 git --exec-path 輸出的目錄中依然有 git-xyz 這些腳本,你還是可

❾ linux系統下怎麼使用git

git命令是用來管理文件的程序,它十分類似DOS下的Norton Commander,具有互動式操作界面。它的操作方法和Norton Commander幾乎一樣:
git pull:從其他的版本庫(既可以是遠程的也可以是本地的)將代碼更新到本地,例如:'git pull origin master'就是將origin這個版本庫的代碼更新到本地的master主枝,該功能類似於SVN的update
git add:是將當前更改或者新增的文件加入到Git的索引中,加入到Git的索引中就表示記入了版本歷史中,這也是提交之前所需要執行的一步,例:'git add app/model/user.rb'就會增加app/model/user.rb文件到Git的索引中
git rm:從當前的工作空間中和索引中刪除文件,例如'git rm app/model/user.rb'
git commit:提交當前工作空間的修改內容,類似於SVN的commit命令,例如'git commit -m story #3, add user model',提交的時候必須用-m來輸入一條提交信息
git push:將本地commit的代碼更新到遠程版本庫中,例如'git push origin'就會將本地的代碼更新到名為orgin的遠程版本庫中
git log:查看歷史日誌
git revert:還原一個版本的修改,必須提供一個具體的Git版本號,例如'git revert ',Git的版本號都是生成的一個哈希值
git branch:對分支的增、刪、查等操作,例如'git branch new_branch'會從當前的工作版本創建一個叫做new_branch的新分支,'git branch -D new_branch'就會強制刪除叫做new_branch的分支,'git branch'就會列出本地所有的分支
git checkout:Git的checkout有兩個作用,其一是在不同的branch之間進行切換,例如'git checkout new_branch'就會切換到new_branch的分支上去;另一個功能是還原代碼的作用,例如'git checkout app/model/user.rb'就會將user.rb文件從上一個已提交的版本中更新回來,未提交的內容全部會回滾
git rebase:用下面兩幅圖解釋會比較清楚一些,rebase命令執行後,實際上是將分支點從C移到了G,這樣分支也就具有了從C到G的功能

熱點內容
快存儲組件 發布:2024-10-26 01:25:43 瀏覽:846
電腦內存不夠租用伺服器 發布:2024-10-26 01:19:03 瀏覽:598
氟壓縮機房 發布:2024-10-26 01:09:45 瀏覽:405
httpurlconnection緩存 發布:2024-10-26 01:04:24 瀏覽:810
三星手機鎖屏怎麼設置密碼 發布:2024-10-26 01:00:35 瀏覽:847
計劃排程演算法 發布:2024-10-26 00:48:08 瀏覽:8
網站伺服器搭建與管理實訓報告 發布:2024-10-26 00:30:56 瀏覽:746
秦遙控駕駛是哪個配置 發布:2024-10-26 00:25:48 瀏覽:848
神鵰俠侶伺服器連接超時怎麼回事 發布:2024-10-26 00:25:28 瀏覽:381
11系統如何安裝安卓應用 發布:2024-10-26 00:22:40 瀏覽:713