Git 笔记:以下内容来源与廖雪峰的官方博客个人所感,部分搬运,详情请看下面地址:
廖雪峰的博客:博客地址
关于Git ,最重要的是三个区:工作区,暂存区,版本库 , 之后的一些操作全部是围绕这三个区进行的。
图片取自廖雪峰博客
工作区:也就是本地区,由git init 创建形成。即使用git init 命令,该目录下就是一个工作区,它会自动在该目录下生成一个.git文件。
命令有: git add filename
暂存区:该区存放工作区进行git add 操作后的临时文件。
命令有: git rm filename
git commit -m "备注提交的内容";
版本库: 该区是暂存区通过git commit命令提交,把暂存区的内容全部提交入该区。
另外的一些命令:git status,查看修改或提交状态
git reset head filename ---> git checkout --filename 还原已经提交到暂存区的修改
git diff 查看的是工作区和暂存区的不同
git log
git reflog
远程仓库github 与本地Git建立连接
一:首先在本地仓库下 ssh-keygen -t rsa -C "your email@example.com" 一路回车
在当前用户主目录下找到.ssh目录,里面有id_rsa和id_rsa.pub
在github的个人头像Setting ----> SSH and GPG keys --->new SSH keys
把id_rsa.pub内的内容赋值到key输入框下。title随意写。 最后Add SSH key
二:在git上创建repository
三:进行本地git 和远程github进行关联
git remote add origin 新建respository的地址
把本地库推送到远程github库
git push -u origin master (-u 参数为新建远程仓库为空,之后不用添加)
先到这..........
二:创建分支
查看分支:git branch
创建分支:git branch <name>
切换分支:git checkout <name>
或者git switch <name>
创建+切换分支:git checkout -b <name>
或者git switch -c <name>
合并某分支到当前分支:git merge <name>
删除分支:git branch -d <name>
后面添加
…or create a new repository on the command line
echo "# DB-travel" >> README.md git init git add README.md git commit -m "first commit" git remote add origin https://github.com/git账户/DB-travel.git git push -u origin master
…or push an existing repository from the command line
git remote add origin https://github.com/git账户/DB-travel.git git push -u origin master