Mac下git使用
- git下载安装
git下载地址
http://sourceforge.net/projects/git-osx-installer/ - git配置
配置个人的用户名称和电子邮件地址
git config --global user.name "runoob"
git config --global user.email test@runoob.com
注:如果用了 --global 选项,那么更改的配置文件就是位于你用户主目录下的那个,以后你所有的项目都会默认使用这里配置的用户信息。
如果要在某个特定的项目中使用其他名字或者电邮,只要去掉 --global 选项重新配置即可,新的设定保存在当前项目的 .git/config 文件里。
- git 创建本地仓库
mkdir Git
cd Git
git init
该命令执行完后会在当前目录生成一个 .git 目录,对应git的配置在改目录的config文件中
- git下载代码
- https需账号密码
git clone https://github.com/project/repo.git
- 默认ssh端口为22时,需配置ssh key
git clone git@github.com:project/repo.git
- ssh 端口非22时,需加上ssh和端口号
git clone ssh://git@hostname:port/.../xxx.git
- git 更新代码
git pull
- git查看分支
git branch
- 创建分支
git branch (branchname)
注:可以用git checkout -b (branchname) 命令来创建新分支并立即切换到该分支下
- 删除分支
git branch -d (branchname)
- git切换分支
git checkout (branchname)
- git 提交代码(三部曲)
- git add 将该文件添加到缓存,添加完成后可以用git status 查看是否已经添加成功,git reset HEAD 文件名 用于取消已缓存的内容。
git add *.c
git add README
git 提交单个文件,提交所有修改文件用
git add .
- git commit 将缓存区内容添加到仓库中
git commit -m '初始化项目版本'
- git push 推送你的新分支与数据到某个远端仓库命令
git push origin 仓库名称