Git的一些实用命令
转眼之间我来到公司已经一个月了,回想着一个月的变化,接触的东西还是有很大的变化。比如 git
。网上也有很多关于git
的基础命令,比如Chillax’s blog–Git常用的基础命令,但是我更想实例化些。下面我就把这些命令放在具体的实例当中来演示。
一、如何把本地的项目放到自己的远程仓库(‘repository’)
在这个例子当中我是使用的 github
上的远程仓库,如果没有 github
的账号申请一个也是so easy.
首先进入到你想要上传的项目文件夹,然后初始化:
git init
。1git init添加远程仓库,在此默认你已经在
github
创建了你的版本仓库,比如我的远程仓库地址是:git@github.com:carpentercloud/testdist.git
1git remote add origin git@github.com:carpentercloud/testdist.git远程仓库已经添加好,接下来就是把本地文件上传到远程仓库
123git add . #跟踪所有文件,别忘了add与.有个空格git commit -m "写下你对提交的描述" #提交所跟踪的文件ggpush #推送到远程仓库
二、如何在github的仓库中展示自己的项目,即 index.html
这里要说一下,要想在github
上看到自己的项目展示,首先你得新建一个分支,废话不多说,还是上图来的快些
- 点击branch,输入新的分支名字
- 点击设置
- 找到Github Pages,你就能看到生成的项目展示地址
二、Git配置
查看已有的配置信息
1git congfig -l配置全局用户信息
12git congfig --global user.name "carpenterCloud"git congfig --global user.email "489644864@qq.com"配置当前用户信息
12git congfig user.name "Cloud"git congfig user.email "489644864@qq.com"
三、Git常用的一些命令
查看已有的配置信息
1git congfig -l获取帮助,例如获取config命令的帮助信息
1git help congfig初始化新仓库
1git init跟踪文件(将文件加到暂存区)
12git add 文件名 #具体某个文件git add . #跟踪全部文件提交更新
1git commit -m "你的描述"上传/推送到仓库
1git push origin master #推送到主分支从远程仓库克隆
1git clone git@github.com:youname/project.git检查当前文件状态
1git status创建.gitignore文件
1touch .gitignore查看修改之后有没有暂存起来
1git diff移除文件
1git rm 文件名重命名文件
1git mv oldname.txt newname.txt查看提交历史
1git log取消暂存文件
1git reset HEAD 文件名添加远程仓库(远程仓库已建好)
1git remote add origin 你的远程仓库地址从远程仓库抓取数据(还没有用过)
1git fetch [remote-name]远程仓库的删除
1git remote rm origin创建分支
1git branch branch-name切换分支
12git checkout branch-namegit checkout -b branch-name #创建并切换的该分支
查看所有分支
1git branch删除分支
12git branch -d branch-namegit branch -D branch-name #强制删除,不会提示错误信息合并分支
1git merge branch-name #先切换到主分支再合并暂存本地修改和恢复本地修改
1234567git stash # save uncommitted changes# pull, edit, etc.git stash list # list stashed changes in this gitgit show stash@{0} # see the last stashgit stash pop # apply last stash and remove it from the listgit stash --help # for more info
以上基础命令参考博客地址:Chillax’s blog–Git常用的基础命令.
如果想进一步理解git可以查看:常用 Git 命令清单
-- EOF --
本文链接:http://yoursite.com/2016/09/09/2016/git的一些常用命令/
发表于2016-09-09 13:33:23,并被添加「 git , 随笔 」标签,最后修改于2019-02-12 20:36:18