git使用记录一:配置账户信息

配置的级别

  • git config --gloabal 针对当前用户下所有的项目 设置
  • git config --local 针对当前工作区的项目来进行设置
  • git config --system 针对当前系统下所有的账户进行设置

配置账户信息

  • git config --global user.name 'soaeon' 设置昵称
  • git config --global user.email 'soaeon@163.com' 设置邮箱
  • git config --global http.postBuffer 524288000 设置文件最大上传容量500M
  • ssh-keygen -t rsa -C 'soaeon@163.com' 生成key :C:Userssoaeon.ssh 将公钥复制到gitlab/github

清除错误的属性

  • git config --global --unset key(属性名字,比如: http..postbuffer)

克隆项目/初始化仓库

如果项目已经存在, 那么 git clone 克隆项目吧

git clone http://xxx.xxx.com/asd/asxc.git

如果项目不存在, 跳转到项目目录下, 初始化

git init

git 三个区的解释

工作区: 本地的工作目录

暂存区: commit 之后是将工作区的内容提交到 暂存区域

远程区: remote origin 这个才是真正的提交到git的远程仓库了

最简单的提交

查看文件的状态

git status

将文件加入

git add index.html

提交

git commit -m 'commit index.html'

暂存区的文件需要修改名字

git mv 原文件名 新文件名字

git mv index.html inde.html

修改完可以直接提交到暂存区

git commit -m 'move index.html to inde.html'

通过 git log 查看最近的演变

查看git 提交的历史

git log

以简洁的方式查看git的log

git log --oneline

查看最近两次的提交

git log -n2

以图形化的方式简单的查看提交的历史

git log --oneline --graph

关于分支的使用

查看所有的分支

git branch

创建分支testing

git branch testing

切换到分支testing

git checkout testing

查看每一个分支最后一次的提交

git branch -v

创建并且切换到分支demo

git checkout -b demo

删除一个分支

git branch -d hotfix

强制删除一个分支

git branch -D hotfix

查看本地分支和远程分支

git branch -va

将hotfix分支合并到master分支

  • 切换到master分支
  • 执行命令 合并到master git merge hotfix

如果两个分支修改了同一个文件呢

还原场景:

  1. hotfix 分支修改 hot.html文件
  2. hotfix 提交 git add hot.html , git commit -m 'upadte'
  3. 切换到master分支 git checkout master
  4. 修改hot.html 文件 vi hot.html
  5. 提交修改 git add hot.html , git commit -m 'master update hot.html'
  6. 执行合并 git merge hotfix

这个时候 有冲突的提示:

解决方法1: git mergetool

解决方法2:使用 git status 查看状态, 然后使用vi hot.html 编辑文件

原文地址:https://www.cnblogs.com/soaeon/p/10896818.html