发现之前的笔记做的太乱,所以今天花点时间重新整理了Git相关的知识
git 命令
- git pull: 从远程对应的分支拉取代码
- git fetch: 获取远程对应分支的更新
- git push [remote] [branch]: 推送到远程指定的分支,参数不指定默认推送主分支
- git push -u origin [branch]: 推送当前分支到指定的远程分支
- git merge [branch]: 将指定分支合并到当前分支
- git merge [branch]: 将指定分支合并到当前分支
- git remote -v: 查看远程仓库
- git checkout -b [branch] [remote name]/[branch]: 创建新的分支,并且追踪指定的远程分支,
- git checkout [branch]: 切换到本地的另外一个分支上
- git checkout -- [filename]: 撤销某个文件本地的改动
- git branch -a: 查看本地和远程的所有分支情况
- git branch -d [branch]: 删除本地指定的某个分支,不能删除当前分支,需要切换
- git branch -r -d origin/ [branch]: 删除远程的某个分支
- git ls-remote: 获取远程引用的完整列表
- git reset --soft HEAD~[index]: 撤销本地的index个提交
- git reset --hard [commit_id]: 回滚到某个提交的时刻
- git rebase [master] [server]: 将server分支中的修改变基到master上
- git stash: 将当前分支的改变暂存起来
- git stash apply:恢复当前分支暂存的改变
- git add [filename]:将某个文件添加到git追踪中
- git add -A:将当前目录下所有的文件都添加到git追踪中
- git commit -a -m "[comment message]":一步操作直接提交当前所有的变动到本地
打tag
- git tag -a [tag name] -m "command message":在当前分支打tag
- git push origin [tag name]":将tag推送到远程
本地分支和远程分支建立关系
- cd existing_folder
- git init
- git remote add origin [remote git url]
- git add .
- git commit
- git push -u origin master
git的fork教程
- 首先在Github上面fork你想要commit的项目,fork完以后,你自己的Github仓库中就有会副本工程
- 克隆下来那个对应的副本工程,你自己的仓库中
- 对副本工程进行提交修改
- 改完之后提交push到远程的副本工程中
- 在Github上面的副本工程中创建一个新的pull request,填上自己的comment
- 创建成功以后,你的这个请求就到了你想要commit的项目那边的pull request里面去了
- 等到项目的主人合并同意了你的pull request之后,那么你就可以在那个项目上面看到你的提交了
Github上面如何查看某个项目的提交记录
- https://github.com/{username}/{project}/commits