当前位置:首页 » 操作系统 » 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的功能

热点内容
破解qq空间访问权限2015 发布:2024-10-26 03:27:52 浏览:173
网页短信源码 发布:2024-10-26 03:25:32 浏览:167
android实现圆角 发布:2024-10-26 03:24:55 浏览:717
科雷服务器ip 发布:2024-10-26 03:24:42 浏览:872
linux找回删除文件 发布:2024-10-26 03:21:46 浏览:581
云服务器不能登录天猫后台 发布:2024-10-26 03:21:01 浏览:104
我的世界116起床服务器 发布:2024-10-26 03:19:35 浏览:72
modelsim脚本 发布:2024-10-26 02:58:09 浏览:174
饥荒开的服务器怎么开全图 发布:2024-10-26 02:55:23 浏览:403
我的世界服务器到上限内存了怎么办 发布:2024-10-26 02:55:23 浏览:787