• git remote add origin git@github.com:myaccount/myproject.git
• git push -u origin master
• git init--------建立repository
• git 命令 --help-----------查看帮助命令
• touch filename
• git status------查看状态
• git add filename--------加入文件到临时的东东
• git add . --------加入所有文件到临时的东东
• git commit -m "add the file filename" -----commit到repository中
• git log------查看日志
• echo "ddd" > filename ------修改filename(先清空)
• git add filename
• git commit -m "filename changed"
• git commit -a -m "filename changed"
• git diff 版本一 版本二--------比较不同
• git reset 版本号--------返回到版本号
• git revert 版本号--------撤销到版本号
• git checkout filename------撤销当下没有git add的动作
• git branch-------参看分支信息
• git branch develop-----建立分支
• git checkout develop-----切换分支
git merge develop------合并分支(将develop merge到master上,develop不变)
提交到github仓库
-- git add . //指的是把所有文件 添加到本地repository
-- git commit -m "test" //这里是添加commit的message
-- git push origin master //origin指的是remote 远端地址, master 指的是你的分支。
http://help.github.com/mac-set-up-git/
git pull origin master 从服务器上拉取信息
git remote 查看repository上的所有分支
git branch -a 查看所有分支
git branch -r 查看远程分支
git branch -d *** //删除分支
git branch *** //新建分支
git checkout ***//切换分支
git status //查看状态
git remote add upstream https://github.com/winterIce/testTitle.git(别人的repository) // 新建分支用于存放别人的repository
git clone https://github.com/winterIce/testTitle.git 克隆到本地
总结一下Ubuntu下github常用的命令,设置部分跳过,假设repository的名字叫hello-world:
1.创建一个新的repository:
先在github上创建并写好相关名字,描述。
$cd ~/hello-world //到hello-world目录,本地目录名与repository的名字不一定相同
$git init //初始化
$git add . //把所有文件加入到索引(不想把所有文件加入,可以用gitignore或add 具体文件,见下文)
$git commit //提交到本地仓库,然后会填写更新日志( -m “更新日志”也可,如$git commit -m “my first vesion of ...”)
$git remote add origin git@github.com:WadeLeng/hello-world.git //增加到remote
$git push origin master //push到github上
2.更新项目(新加了文件):
$cd ~/hello-world
$git add . //这样可以自动判断新加了哪些文件,或者手动加入文件名字
$git commit //提交到本地仓库,不加参数会提示,注意:^=Ctrl,按照提示来就好了~~~
$git push origin master //不是新创建的,不用再add 到remote上了
3.更新项目(没新加文件,只有删除或者修改文件):
$cd ~/hello-world
$git commit -a //记录删除或修改了哪些文件
$git push origin master //提交到github
4.忽略一些文件,比如*.o等:
$cd ~/hello-world
$vim .gitignore //把文件类型加入到.gitignore中,保存
然后就可以git add . 能自动过滤这种文件
5.clone代码到本地:
$git clone git@github.com:WadeLeng/hello-world.git
假如本地已经存在了代码,而仓库里有更新,把更改的合并到本地的项目:
$git fetch origin //获取远程更新
$git merge origin/master //把更新的内容合并到本地分支
6.撤销
$git reset
7.删除
$git rm * // 不是用rm
//------------------------------常见错误-----------------------------------
1.$ git remote add origin git@github.com:WadeLeng/hello-world.git
错误提示:fatal: remote origin already exists.
解决办法:$ git remote rm origin
然后在执行:$ git remote add origin git@github.com:WadeLeng/hello-world.git 就不会报错误了
2. $ git push origin master
错误提示:error:failed to push som refs to
解决办法:$ git pull origin master //先把远程服务器github上面的文件拉先来,再push 上去。
//------------------------------------------------------------------------------
了解github
Git是用C语言开发的分布版本控制系统。版本控制系统可以保留一个文件集合的历史记录,并能回滚到另外一个状态(历史记录状态)。对 于任何一个文件,在 Git 内都只有三种状态:已提交(committed),已修改 (modified)和已暂存(staged)。已提交表示该文件已经被安全地保存在本地数据库中了;已修改表示修改了某个文件,但还没有提交保存;已暂 存表示把已修改的文件放在下次提交时要保存的清单中。
一般情况下,Git的命令都是git [command] [option] [argument]格式。其中 command指的是某种操作命令,比如config,mv,rm,pull,push等等。而option和 argument指的是操作命令后面的具体参数,比如:
git config --golobal user.name="hic" 其中,config指的就是配置命令,接着后面跟上配置的具体参数,其中–global指的是对全局配置生效,后面的user.name就是对用户名进行设置。
配置文件是从事所有所有工作的基础,在这里配置文件决定了工作时候的用户,邮箱,以及默认编辑器等等常用的配置参数,下面就先说一说配置文件。
在Git中,配置文件有三大类,分别放在不同的位置。
注意:每一级别的配置,都会覆盖上层的相同配置。
用户名设置
电子邮件
设置文本编辑器,默认为vi,这里设置为emacs
查看配置信息
如果要查看某个特定的环境变量,只要把它的名字放到最后即可
选择一个工作目录,开始工作,同时我们添加一些文件和目录。
执行这条命令之后,在test目录下会出现一个隐藏的.git目录,该目录会保存工程中所有的信息。
如果事先没有作出任何的更改,一个项目是没有分支的,它只有一条主线,例如:
这里master就是主干,就是整个开发的流程,它前面的星号表示当前开发的流程。
如果在开发过程中,我们突然需要添加某个功能,或者打上某个补丁,可以在 master主干上添加一个分支,比如host,例如:
这个时候,你可以清楚的看到星号已经在host头上,表示当前已经切换到host上,你可以开发你的补丁,而不会打乱主干的开发。
如果你在开发过程中想要回到主干,可以使用checkout命令进行切换。
此时,你又回到主干了。
当某个分支的开发结束后,你会需要将其合并到主干上,从而集中精力进行主干的开发。合并前只需要将指针切换到主干,即master,然后使用merge命令。
此时的host分支已经失去作用了,可以将删除。
配置 Git Editor
安装 GHfW 之后默认调用的 editor 是 GitPad,但是我没运行成功,单独安装也不行,不知道为何,索性切换到 vim。相关命令为:
git config --global core.editor vim
配置中文支持
虽然现在已经可以运行 git 命令行,但是对中文处理有很多问题,工作中避免不了处理中文,所以下面进行中文相关的配置。
对于中文文件,个人习惯文件内容统一使用 utf-8 编码,这样在多平台使用的时候可以避免很多问题。
Git 中文文件名支持
git add
的时候,中文会显示成"“\344\270\255\346\226\207.txt",使用如下命令进行配置:
git config --global core.quotepath false
ls 显示中文
使用 vim 编辑 ~/.bashrc
,添加以下内容(如没有则新建一个):
export LANG=en_US.utf-8
alias ls='ls --show-control-chars --color=auto'
vim 中文支持
使用 vim 编辑 ~/.vimrc
,添加以下内容:
set encoding=utf-8
set termencoding=gbk