创建Git存储库
从现有目录 |
cd project_dir |
git init |
git add . |
从其他存储库 |
git clone existing_dir new_dir |
git clone git://github.com/user/repo.git |
git clone https://github.com/user/repo.git |
Git - 本地更改
在工作目录中更改 |
git status |
跟踪的文件更改 |
git diff |
添加更改的文件 |
git add file1 file2 file3 |
删除文件 |
git rm file |
git rm dir/ -r |
(recursive under directory) |
查看准备好提交的文件 |
git diff --cached |
提交更改 |
git commit |
git commit -m "My message" |
git commit -a -m "My Message" |
(tracked files only, auto add) |
更改最后提交 |
git commit --amend |
将更改还原到文件 |
git checkout -- file |
还原更改(新提交) |
git revert HEAD |
返回上一个提交状态 |
git reset --hard HEAD |
Git - 历史
显示所有提交 |
git log |
短格式 |
git log --pretty=short |
补丁Patches |
git log -p |
显示文件提交 |
git log file |
显示目录提交 |
git log dir/ |
Stats |
git log --stat |
谁更改了文件 |
git blame file |
Git - 合并/Rebase
合并分支到当前 |
git merge branch |
Rebase进入分支 |
git rebase branch |
git rebase master branch |
中止rebase |
git rebase --abort |
合并工具来解决冲突 |
git mergetool |
Conflicts against base file |
git diff --base file |
与其他用户进行比较 |
git diff --theirs file |
Diff您的更改 |
git diff --ours file |
解决冲突后 |
git rebase --continue |
Git - Remote更新/发布
列出remotes |
git remote -v |
显示信息 |
git remote show remote |
添加remote |
git remote add path/url |
获取更改 |
git fetch remote |
获取+合并 |
git pull remote branch |
将本地发布到远程 |
git push remote branch |
删除远程分支 |
git push remote :branch |
发布标签 |
git push --tags |
Git - 分支/标记
列出分支 |
git branch |
切换到分支 |
git checkout branch |
创建新分支 |
git branch new |
从现有的创建分支 |
git branch new existing |
删除分支 |
git branch -d branch |
标记当前提交 |
git tag tag-name |