1 初始化

  • git init
  • git config --global/--local user.name "xxx"
  • git config --global/--local user.email "xxx"
  • git config --global http.postBuffer 524288000 可提高传输速度
  • git config --global --list 查看配置信息

其中--global可以替换为 --local 或者--system,项目中优先级为

--local > --global >--system

2 添加远程库

  • git remote add origin url(git@xxxx.git)
  • git remote -v 查看远程库配置情况

3 添加与提交

  • git add file-name把文件添加到仓库git add .表示添加新文件和编辑过的文件, git add -A表示添加所有内容
  • git commit -m "提交说明"把所有add的文件提交到仓库

4 分支操作

查看分支

  • git branch
  • git branch -a:查看所有分支包括远程分支

新建分支

  • git branch new_branch

删除分支

  • git branch -d branch_name

重命名分支

  • git branch -m branch_name new_branch_name

切换分支

  • git checkout branch_name
  • git checkout -b branch_name:新建并切换到该分支
  • git checkout -- file_name:在 git add之前撤销对文件的修改
  • git checkout .:在 git add之前撤销对所有文件的修改

合并分支

  • git merge other_branch:把other_branch合并到当前分支,无必要不会产生一个合并提交
  • git merge --no-ff other_branch:合并后建立一个合并提交

5 记录

  • git log:显示所以提交记录
  • git log --pretty=oneline:以单行显示一次commit

6 文件状态模型

  • 未跟踪:untracked
  • 未修改:unmodified
  • 已修改:modified
  • 已暂存:staged
git状态模型

7 版本回退

  • git reset HEAD~x:将HEAD指针调整到之前的x次提交
    • 默认参数--mixed,只舍弃提交,缓存区和工作区内容不变
    • --hard:舍弃提交,缓存区和工作区都会变
    • --soft:舍弃提交,缓存区和工作目录都不变
  • git log --oneline :获取每次提交的短hash值(hash可标定地址?)
  • git reset short_hash~x:将hash值所代表的提交调整到之前的x次提交
  • checkout cmt-id :HEAD回合当前分支分离
  •  

8 git diff

git diff 详解

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注