克隆仓库
git clone http://git.oschina.net/yiibai/git-start.git
git clone http://git.oschina.net/yiibai/git-start.git mygit
管理已有仓库
# 初始化
git init
# 跟踪文件/将文件放到暂存区
git add hello.py
git add FileFold
# 暂存所有文件
git add .
# 提交
git commit
git commit -m 'initial project version'
git commit -a -m 'added new benchmarks'
# 重新提交(抹除上次提交)
git commit --amend
# 提交历史
git log
git log --pretty=oneline
# 查看最近2次提交差异
git log -p -2
# 查看提交统计信息
git log --stat
# 检查文件状态
git status
git status -s
git status --short
# 查看暂存后的更新部分
git diff
# 查看已暂存的更新部分
git diff -cached
# 绿色的内容表示添加,红色的内容表示删除
# 删除文件
git rm file_name
git rm -f file_name
# 重命名/移动文件
git mv file_from file_to
# 取消暂存
git reset HEAD <file>
撤销修改
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
renamed: README.md -> README
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: mytext.txt
(按照提示进行操作即可)
忽略文件
cat .gitignore
远程仓库
# 查看远程仓库
git remote
git remote -v
# 添加远程仓库
git remote add <shortname> <url>
# 从远程仓库中获得还没有的数据
git fetch [remote-name]
# 推送到远程仓库
git push [remote-name] [branch-name]
# 查看远程仓库信息
git remote show [remote-name]
# 重命名远程仓库
git remote rename <oldname> <newname>
# 移除仓库
git remote rm <name>