今天给各位分享linux如何搭建git的知识,其中也会对Linux如何搭建apache进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
1、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就提交的话,只会提交第一次的修改。命令详解可查看“Linux命令大全”。
2、如何搭建linux git服务器
首先我们分别在Git服务器和客户机中安装Git服务程序(刚刚实验安装过就不用安装了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, product-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 root@linuxprobe.com
The key's randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+
将客户机的公钥传递给Git服务器:
[root@linuxprobe ~]# ssh-copy-id 192.168.10.10
root@192.168.10.10'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 root@192.168.10.10:/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 "root@linuxprobe.com"
[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 root@192.168.10.10:/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 root@192.168.10.10:/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 root@192.168.10.10:/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的,中间有一部分是怎么去搭建,你可以看下
3、怎样在linux 上搭建git +apache服务器
1:服务器端创建用户(git)
# sudo addusergit
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
4、ubuntu虚拟机linux下怎么创建git仓库
一、 在 Ubuntu 系统中部署 Git Server
在Ubuntu系统中,这一步相当简单,只需要在Terminal中输入
sudo apt-get update
完成这一步后,就可以安装 git core 组件,通常情况下,安装在系统中的git 只是一个简单的客户端,包括一些最基本的命令以及特性,而作为保管代码的仓库,则还需要其他特性支持,所以需要安装 git core,如果之前已经安装了 git,那么仍然需要安装 git core
sudo apt-get install git-core
二、配置Git Server
完成这两步之后,就可以开始配置 Git Server 了。
增加 developers 组以及创建保存项目的仓库
需要创建一个新的用户组,并且将创建的仓库都放置在名为 git 的用户下,当然git 要隶属于 developers 组,这样也是为了方便将来的管理需要。
sudo groupadd developers
cd /home/
sudo mkdir git
sudo useradd git -d /home/git
以上四个命令分别为创建 developers 用户组, 并在/home/ 文件夹下为名为 git 的用户创建工作目录,创建名为 git 的用户账户并将它的工作目录指向/home/git。
之后,需要将增加的用户添加到 developers 用户组中,这一步一般通过修改/etc/group 文件达成,在正式修改 /etc/group 文件前或许需要先做一个备份。找到创建的用户组,譬如例子中创建的 developers。或许能在文件中看到类似的一行:
linux如何搭建git的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于Linux如何搭建apache、linux如何搭建git的信息别忘了在本站进行查找喔。