目录
git config --global push.default simple
git remote add origin root@192.168.84.31:/var/git/sph
git remote add origin git:/192.168.84.31/project
git remote set-url origin http://git.XXXX.com/XXX/XXX.git/
git init /var/git/project --bare
/usr/lib/systemd/system/git@.service
git clone git://192.168.84.31/project
Git学习记录
时间:2024-08-22
作者:垃圾宝宝
初始化仓库
Git init
Git init project --bare
设置远程仓库和克隆时区别末尾一个有.git\一个没有
查看提交的记录
git log --pretty=oneline
[root@db01-84-31 project]# git log --pretty=oneline
85e931808a3b0c7d0ead5157f1b9d4c4cbaa7415 第二次提交
c89a0857cc3856835da23d267eeb6dbafb4cfcca init data submit
查看当前git远程库地址
git remote -v
// -v 是 --verbose 的简写
git remote -v
查看详细提交记录
git log
[root@db01-84-31 project]# git log
commit 85e931808a3b0c7d0ead5157f1b9d4c4cbaa7415
Author: Your Name <you@example.com>
Date: Thu Aug 22 18:30:24 2024 +0800
第二次提交
commit c89a0857cc3856835da23d267eeb6dbafb4cfcca
Author: Your Name <you@example.com>
Date: Thu Aug 22 18:24:51 2024 +0800
init data submit
撤出暂存区的文件
git reset HEAD file(.代表全部文件)
[root@db01-84-31 project]# git status
# 位于分支 master
# 要提交的变更:
# (使用 "git reset HEAD <file>..." 撤出暂存区)
#
# 新文件: commit3.txt
#
[root@db01-84-31 project]# git reset HEAD commit3.txt
[root@db01-84-31 project]# git reset HEAD .
提交数据到远程仓库
git config --global push.default simple
git push
[root@db01-84-31 project]# git config --global push.default simple
[root@db01-84-31 project]# git push
root@192.168.84.31's password:
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (8/8), 646 bytes | 0 bytes/s, done.
Total 8 (delta 0), reused 0 (delta 0)
To root@192.168.84.31:/var/git/project
* [new branch] master -> master
查看当前提交版本
git reflog
[root@db01-84-31 project]#
85e9318 HEAD@{0}: clone: from root@192.168.84.31:/var/git/project
查看所有提交版本
git log --oneline
[root@db01-84-31 project]# git log --oneline
85e9318 第二次提交
c89a085 init data submit
移动提交版本
git reset --hard
[root@db01-84-31 project]# git log
commit 85e931808a3b0c7d0ead5157f1b9d4c4cbaa7415
Author: Your Name <you@example.com>
Date: Thu Aug 22 18:30:24 2024 +0800
第二次提交
commit c89a0857cc3856835da23d267eeb6dbafb4cfcca
Author: Your Name <you@example.com>
Date: Thu Aug 22 18:24:51 2024 +0800
init data submit
[root@db01-84-31 project]# git reset --hard 85e9318
HEAD 现在位于 85e9318 第二次提交
查看分支
git status
git branch -v
当前
[root@db01-84-31 project]# git status
# 位于分支 master
无文件要提交,干净的工作区
所有
[root@db01-84-31 project]# git branch -v
* master 85e9318 第二次提交
创建分支
git branch dev
[root@db01-84-31 project]# git branch dev
切换分支
git checkout dev
[root@db01-84-31 project]# git checkout dev
切换到分支 'dev'
添加远程仓库服务器地址
git remote add origin root@192.168.84.31:/var/git/sph
ssh协议
git remote add origin root@192.168.84.31:/var/git/sph
git remote add origin git:/192.168.84.31/project
git协议
git remote add origin git:/192.168.84.31/project
直接修改远程 origin 的git仓库地址
git remote set-url origin http://git.XXXX.com/XXX/XXX.git/
Git协议服务器
yum install -y git-daemon
git init /var/git/project --bare
/usr/lib/systemd/system/git@.service
[root@db01-84-31 project]# vim /usr/lib/systemd/system/git@.service
[Unit]
Description=Git Repositories Server Daemon
Documentation=man:git-daemon(1)
[Service]
User=nobody
ExecStart=-/usr/libexec/git-core/git-daemon --base-path=/var/git --export-all --user-path=public_git --syslog --inetd --verbose
StandardInput=socket
systemctl start git.socket
git clone git://192.168.84.31/project
[root@db01-84-31 tmp]# git clone git://192.168.84.31/project
正克隆到 'project'...
remote: Counting objects: 8, done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 8 (delta 0), reused 0 (delta 0)
接收对象中: 100% (8/8), done.
[root@db01-84-31 tmp]# ll
总用量 0
drwxr-xr-x 4 root root 46 8月 22 20:06 project
[root@db01-84-31 tmp]#
Git http服务期
yum install -y httpd gitweb
vim /etc/gitweb.conf
$projectroot = "/var/git";