Git小结

作者: fengfancky | 来源:发表于2018-05-21 19:46 被阅读12次

来源:
Git教程-廖雪峰的官方网站

安装Git并设置

安装完成后打开Git Bash设置:

 git config --global user.name "Your Name"
 git config --global user.email "email@example.com"

创建版本库

先转到指定目录下,cd

git init

添加文件

 git add <file>

把目录下所有文件都添加到该仓库中(使用.)

git add .

提交文件到仓库

git commit -m <message>

查看日志

查看提交日志:

git log

简化提交日志信息

git log --pretty=oneline

查看输入的命令日志:

git reflog

查看分支合并图:

git log --graph

版本回退

回到上一个版本:

git reset --hard HEAD^

回到指定版本:

git reset --hard commit_id

工作区和暂存区

工作区有一个隐藏目录.git,这个不算工作区,而是Git的版本库。

image
  • 第一步是用git add把文件添加进去,实际上就是把文件修改添加到暂存区;
  • 第二步是用git commit提交更改,实际上就是把暂存区的所有内容提交到当前分支。

查看当前状态

git status

撤销修改

工作区的修改全部撤销:

git checkout -- <file>

把暂存区的修改撤销掉:

git reset HEAD <file>

删除文件

git rm <file>
git commit -m "remove file"

添加远程仓库

将本地仓库与远程仓库关联:

git remote add origin git@github.com:fengfancky/learngit.git

将本地库内容推送到远程仓库:

git push

或者

fatal: The current branch master has no upstream branch.
To push the current branch and set the remote as upstream, use:

    git push --set-upstream origin master

从远程仓库拉取

git pull

从远程仓库克隆

git clone git@github.com:fengfancky/gitskills.git

创建分支

git branch <name>

创建并切换分支:

git checkout -b <name>

查看分支

git branch

合并指定分支到当前分支

git merge <name>

删除分支

git branch -d <name>

强行删除

git branch -D <branch-name>

查看远程库信息

git remote

获取更详细信息:

git remote -v

推送分支

git push origin master

推送其他分支,如 ,dev:

git push origin dev

创建远程origin的dev分支到本地:

git checkout -b dev origin/dev

相关文章

网友评论

    本文标题:Git小结

    本文链接:https://www.haomeiwen.com/subject/kthadftx.html