git命令
因为经常忘记git命令,所以我记了个笔记。
请随意使用。
创建Git的工作目录
进行git初始化。
Git的注册
以下是原生的汉语释义:
$ git配置 – global 用户. 名字 “{用户名}”
$ git配置 – global 用户. 电子邮件 {yourmail@example.com}
代理的命令如下:
$ git配置 – global http 代理 http://{id}:{pass}@{example.proxy}:8080
$ git配置 – global https 代理 http://{id}:{pass}@{example.proxy}:8080
或者在编辑器中进行编辑(可能更容易一些)
如果使用命令行进行编辑(指定vim)
$ git config –global core.editor ‘vim -c “set fenc=utf-8″‘
下次使用
$ git config –global -e
如果要直接进行更改,请使用以下命令:
$ vi ~/.gitconfig
[user]
name = {UserName}
email = {yourmail@example.com}
[http]
proxy = http://{id}:{pass}@{example.proxy}:8080
[https]
proxy = http://{id}:{pass}@{example.proxy}:8080
[core]
editor = vim -c \"set fenc=utf-8\"
经常使用的东西
添加和提交
$ git commit -am “提交注释!”
在创建新文件时,由于无法使用commit选项a,因此需要在进行commit之前执行$ git add .。
记录
在执行版本切换时,通过git的log命令频繁使用以确认重要的ID和评论。
推荐使用git log命令的–oneline选项来以一行的方式显示日志。
结账
Git的checkout命令可以让您返回到旧版本,以便查看文件的内容或返回到原始位置。
确认您想要返回的ID。
$ git 查看日志
$ git log
commit f7a7cbf614862d468f7afdad4451c91e07911fae
Author: {user} <yourmail@example.com>
Date: Tue Jul 17 09:58:52 2018 +0900
只要ID是唯一确定的,且不与其他ID重复,从前面选择大约五个数字即可。
2. 返回以结账
选择一个由5个数字组成的id来返回位置,以f7a7c作为例子的话,可以使用git checkout命令。
在结账时返回到原始版本
$ 切换到主分支
远程
git的remote需要一个远程目录。
在本例中,为了本地环境,使用目录{dir}代替了URL。
由于 push 处理的是已经提交(commit)的目录配置,
所以在 push 之前需要将工作目录更新到最新状态($ git commit -am “new commit”)。