git init
git add .
git commit -m '第一次提交'
git remote add origin https://github.com/zhenli2017/EveryTest.git
git push origin master
Git 命令
- git config --global user.name ... :设置用户名
- git config --global user.email ... :设置密码
- git config --global credential.helper store :保存账号密码,避免重复输入
- git add . : 把所有文件添加到本地仓库缓存(合并文件时候表示合并文件完成)
新建文件或文件夹的时候要先add,否则文件不会被保存
- git commit -m 'aaa' <文件路径(可有可无,当提交不上去就必须要)> : 保存文件到本地仓库
- git pull origin <主支或分支> : 从网络仓库拉取数据
- git push origin <主支或分支> : 推送数据到网络仓库
- git diff <id>: 查看修改了哪些内容
- git status : 查看状态(合并文件时候可以查看是否已经解决冲突,以及未解决冲突的文件)
- git reset --hard : 返回上一次的版本(取消本次更新)
- git rm <file> : 从版本库中删除文件
- git rm <file> --cached : 从版本库中删除文件,但不删除文件
- git revert <$id> : 恢复某次提交的状态,恢复动作本身也创建次提交对象
- git revert HEAD : 恢复最后一次提交的状态
- git log : 查看提交的日志
- git log -5 : 查看最近5条提交的日志
- git log --stat : 查看提交文件的数量统计
- git log -p : 查看提交文件的修改内容
- git clone <http > : 从网络上克隆项目到本地
Git 小问题
1.file know match (文件不匹配,提交不上去)
这时候commit 的时候要指定文件的具体路径,打开brush的时候最好在.git文件夹同级目录下打开,否则会提交错误,也可能导致文件提交失败
2.merger问题
- 通过vi编辑器编辑冲突文件,
- i 是进入输入模式
- esc返回命令模式
- 想输入命令要使用 :wq (保存退出),:q(退出),!q(不保存退出)
-
3.创建远程分支
git init
git branch 分支
git checkout 分支
git add .
git commit -m '描述'
git remote add [origin] [github地址]
git push origin 分支
删除分支
git branch -d [本地分支](删除本地分支)
git push origin : [远程分支] (删除一个远程分支 ,冒号(:) 表示删除)
4.删除已经保存的账户和密码
1.在c:/user/用户名,找到.git-credentials ,这个文件就是保存的账号和密码
2.删除这个文件,然后重新远程添加项目url
3.git remote add origin <url>
5.push 时候在write object 停住不动
由于文件上传太大,修改git上传文件限制大小就行
git config --global http.postBuffer 524288000
6.搭建git服务器
0.卸载低版本的git
yum remove git
1.下载最新版本的git
https://mirrors.edge.kernel.org/pub/software/scm/git/
2.scp 上传到服务器
3.tar -xvf git... 并 cd
4.编译并安装
make prefix=/usr/local/git all
make prefix=/usr/local/git install (/usr/local/git : 安装的路径)
5.添加git到环境变量
vim /etc/profile
export PATH="/usr/local/git/bin:$PATH" (/usr/local/git/ : 刚才安装的路径)
source /etc/profile (文件立即生效)
git --version
6.添加用户
useradd 用户名
passed 密码
7.生成RSA公钥和私钥
命令 : ssh-keygen -t rsa -C "1179581524@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): (公钥和私钥的存放路径)
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
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:
SHA256:rgzi/itpTsdRD8i3qMhceoQ1Prl6Km0DPO1vUGRlRN4 1179581524@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| += |
| . +o . |
| o= +. E |
| + o= + |
|...*+ . S |
|+++=o. . |
|.**+= . |
|.oX= + . |
|.B*+=oo |
+----[SHA256]-----+'
8.创建证书登录
mkdir /home/git/.ssh
chmod 700 /home/git/.ssh
touch 700 /home/git/.ssh/authorized_keys
chmod 600 /home/git/.ssh/authorized_keys
9.添加客户端的公钥到authorized_keys
10.服务端创建空仓库
git init --bare test.git
11.客户端clone
git clone 用户名@serverIP:/绝对路径/test.git
网友评论