跳到主要内容

简易命令入门

git命令

git学习文档:https://git-scm.com/book/zh

简易入门

Git 全局设置:

git config --global user.name "奥利奥"
git config --global user.email "1669299610@qq.com"

创建 git 仓库:

mkdir oolh
cd oolh
git init
touch README.md
git add README.md #把文件加入暂存区(git ls-files查看暂存区的内容)
git commit -m "first commit"
git remote add origin(仓库名) https://gitee.com/oolh/oolh.git
git push -u origin master

已有仓库?

cd existing_git_repo
git remote add origin https://gitee.com/oolh/oolh.git
git push -u origin master

分支

https://www.runoob.com/git/git-branch.html

查看分支

git branch 列出当前分支清单
git branch -a 查看远程分支和本地分支
git branch -v 查看各个分支最后一个提交信息
git branch --merged 查看哪些分支已经合并入当前分支

创建新的本地分支

  • 新建的分支下的内容和原分支的一样,内容改动后可合并到原分支。分支可以用于新增功能或修改bug。
git branch 分支名 # 基于当前commit创建test分支

切换分支

git checkout 分支名

创建并切换到新分支

git checkout -b 分支名

推送到远程仓库,这会自动在远程仓库中生产新的分支

git push -u 仓库名 分支名

删除分支(要先切换到其他分支)

git branch -d test:删除本地test分支

git branch -D test: test分支还没有合入当前分支,所以要用-D参数才能删掉。

git push origin --delete test 删除远程test分支

git push origin :test 删除远程test分支

分支合并

应用例子理解

https://git-scm.com/book/zh/v2/Git-%E5%88%86%E6%94%AF-%E5%88%86%E6%94%AF%E7%9A%84%E6%96%B0%E5%BB%BA%E4%B8%8E%E5%90%88%E5%B9%B6

git merge branch1 #把branch1合并到当前分支

仓库

查看本地已关联的远程库

git remote -v

关联多个远程库

待学习。。

暂存区

删除暂存区指定文件:
$ git rm --cached readme.txt
清空暂存区:

所谓暂存区实质是.git目录下的index文件,只要将此文件删除,那么就可以认为暂存区被清空。

$ rm .git/index