0%

git 命令

git 命令

创建git用户: useradd git 此用户不允许使用shell,编辑/etc/passwd文件将/bin/bash修改
为/usr/bin/git-shell
cd /home/git目录, 服务端初始化仓库 git init –bare pdf.git 客户端初始化仓库 git init
chown -R git:git pdf.git
配置ssh客户端,在C:\Users\YourUsername.ssh\目录下打开或者新建一个名为config的文件
添加一个配置块:

1
2
3
4
5
Host node.gdfcq.top
User git
HostName abc.com
Port 123
ProxyCommand ncat --proxy 127.0.0.1:1082 %h %p

Host: 主机别名
ProxyCommand: 代理设置
使用git clone abc.com:/home/git/pdf.git

设置免密登录

ssh-keygen命令生成id_rsa.pub公钥,复制公钥内容到/home/git/.ssh/authorize_keys文件内

推送至远程仓库:

1
2
3
git remote add origin git@domain.com:blog.git  
git remote set-url origin ssh://git@domain.com:port/home/git/pdf.git
git push -u origin master

克隆远程仓库

1
git clone ssh://git@domain.com:2222/home/username/demoproject.git

一系列指令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
git push origin --mirror

git branch cleanerbranch
git commit
git push origin cleanerbranch:master

git init
git remote add origin <url-to-remote>
git checkout -b main
git push origin --mirror

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch 要删除文件的相对路径' --prune-empty --tag-name-filter cat -- --all
git push origin master --force --all
如果遇到 fatal: bad revision ‘rm’ 这样的问题,那么你要记住这个命令在 windows 下操作是使用双引号,而不是单引号

查看占用空间大小

1
git count-objects -vH 

查看哪个提交对git.tgz文件产生改动:

1
git log --oneline --branches -- git.tgz

从HEAD指向的分支中移除文件
git filter-branch –tree-filter ‘rm -f passwords.txt’ HEAD 这样再clone的时候就没有passwords.txt这个文件了

filter-branch 的–index-filter选项只会修改在暂存区或索引中的文件,
不会修改在硬盘上检出的文件