安装环境
yum install curl-devel expat-devel gettext-devel \openssl-devel zlib-devel
#安装
yum install git
#指定用户
git config --global user.name lufei
#指定邮箱
git config --global user.email lufei@haizeiwang.com
#添加git仓库
mkdir gitworkspace
#查看状态
git status
#添加文件
git add hello.txt
git commit -m "添加一个文件"
#修改文件名称后
git add --all
#删除一个文件
git rm nihao.txt
git commit -m "delete file nihao.txt"
#推送到远程地址
git push https://github.com/lufei/lufei.git master
#输入用户名和密码后添加成功
#为地址添加别名
git remote lufei https://github.com/lufei/lufei.git
#修改文件后重新添加到远程仓库
git push lufei master
#下载远程git代码
git clone https://github.com/lufei/lufei.git
#更新服务器代码
git pull https://github.com/lufei/lufei.git master
#查看改动日志
git log
commit c1cc17e9d4f0f62ac18a6e46256ab2df404c75d4
Author: lufei<lufei@haizeiwang.com>
Date: Wed Apr 11 15:09:28 2018 +0800
add word
commit a3d6345b754e61de097f2ae52b2bcff194b858c8
Author: lufei<lufei@haizeiwang.com>
Date: Wed Apr 11 14:47:41 2018 +0800
delete file nihao.txt
commit 8ce9088d1a83d9945a7fd059dc2acc6a65ec800e
Author: lufei<lufei@haizeiwang.com>
Date: Wed Apr 11 14:29:52 2018 +0800
add
#查看简单日志
git log --pretty=oneline
#返回版本一个^代表一个版本
git reset --hard HEAD^^
git reset --hard 8ce9088d1a83d
git push -f origin dev
#查看所有日志
git reflog
#查看分支带有*号的是当前分支
git branch
* master
nihao
#添加分支
git branch nihao
#切换分支
git checkout nihao
#合并分支,先切换到master分支
git merge hello
#删除分支(如果没有合并到主线,会有提示)
git branch -d nihao
#强制删除分支(如果没有合并到主线,不会有提示,直接删除)
git branch -D nihao
#查看远程仓库git版本
git remote -v
#删除远程仓库别名(未删除远程仓库)
git remote remove lufei
#修改远程仓库别名
git remote rename lufei lufeichuanzhang
#创建公钥
先修改远程仓库的别名
git remote add lufeissh git@github.com:lufei/lufei.git
邮箱为上面配置时指定的邮箱 注意ssh-keygen没有空格
ssh-keygen -t rsa -C "lufei @haizeiwang.com"
此时输出
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
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.
获取文件/root/.ssh/id_rsa.pub中的内容
登录github,点击头像-settings,点击左侧“SSH and GPG keys”,点击New SSH key,把文件中的内容复制过来,保存,以后再向远程仓库push代码的时候就不用输入密码了
如果代码修改后发现分支错误了
git stash // 执行命令,将修改的代码暂存到stash
git checkout branch // 切换分支
git stash pop // 从stash中取出暂存的代码修改
删除本地分支
git branch -d dev
强制删除本地分支
git branch -D dev
网友评论