本文共 1405 字,大约阅读时间需要 4 分钟。
本文主要是简单介绍下git的基本用法
一、安装
linux中安装很简单,用apt-get install git(centos用yum) 就完成了安装。os x的话,用brew install git。安装好后,在终端敲git,显示如下表示安装成功。
appledeMacBook-Pro:~ apple$ gitusage: git [--version] [--help] [-C安装后再配置下用户和密码] [-c name=value] [--exec-path[= ]] [--html-path] [--man-path] [--info-path] [-p | --paginate | --no-pager] [--no-replace-objects] [--bare] [--git-dir= ] [--work-tree= ] [--namespace= ] [ ]
git config --global user.name "Your Name"git config --global user.email "email@example.com"
二、创建第一个仓库
appledeMacBook-Pro:~ apple$ mkdir test_gitappledeMacBook-Pro:~ apple$ cd test_gitappledeMacBook-Pro:test_git apple$ git initInitialized empty Git repository in /Users/apple/test_git/.git/
查看当前目录下是否有个.git目录
appledeMacBook-Pro:test_git apple$ ls -ah. .. .git
三、提交代码到仓库
添加文件到Git仓库,分两步:
appledeMacBook-Pro:test_git apple$ git add first.pyappledeMacBook-Pro:test_git apple$ git statusOn branch masterInitial commitChanges to be committed: (use "git rm --cached..." to unstage) new file: first.pyappledeMacBook-Pro:test_git apple$ git commit -m "my first commit"[master (root-commit) a5813c6] my first commit 1 file changed, 1 insertion(+) create mode 100644 first.py
首先,你先将要提交的文件用git add <file_name> 加入缓存区(这时候你可以查看缓存区现在有什么东西改变),确定修改后用git commit -m "填写此次提交说明"
转载地址:http://havws.baihongyu.com/