Git 命令
from https://github.com/joshnh/bash_profile/blob/master/.bash_profile
--
初始化和创建工程命令
命令 |
说明 |
git init |
初始化本地 Git 仓库 |
git clone ssh://[email protected]/[username]/[repository-name].git |
从远程仓库复制工程到本地 |
基本操作
命令 |
说明 |
git status |
检查状态 |
git add [file-name.txt] |
添加文件到当前区域 |
git add -A |
添加当前所有新或修改过的文件到当前区域 |
git commit -m "[commit message]" |
添加提交注释信息 |
git rm -r [file-name.txt] |
删除文件或文件夹 |
创建新分支 & 合并分支
命令 |
说明 |
git branch |
列示分支(*为当前分支) |
git branch -a |
列示所有分支:包括本地和远程 |
git branch [branch name] |
创建新分支 |
git branch -d [branch name] |
删除分支 |
git push origin --delete [branchName] |
删除远程分支 |
git checkout -b [branch name] |
创建新分支并切换 |
git checkout -b [branch name] origin/[branch name] |
克隆远程分支并切换至 |
git checkout [branch name] |
切换分支 |
git checkout - |
切换到上次签出的分支 |
git checkout -- [file-name.txt] |
放弃对文件的修改 |
git merge [branch name] |
合并一个分支到当前活跃分支 |
git merge [source branch] [target branch] |
合并一个分支到目标分支 |
git stash |
备份当前的工作区的内容 |
git stash clear |
清空Git栈 |
分享和项目更新
命令 |
说明 |
git push origin [branch name] |
将当前分支推送到origin主机的对应分支 |
git push -u origin [branch name] |
上面命令将本地的master分支推送到origin主机,同时指定origin为默认主机,后面就可以不加任何参数使用git push了 |
git push |
Push changes to remote repository (remembered branch) |
git push origin --delete [branch name] |
Delete a remote branch |
git pull |
Update local repository to the newest commit |
git pull origin [branch name] |
Pull changes from remote repository |
git remote add origin ssh://[email protected]/[username]/[repository-name].git |
Add a remote repository |
git remote set-url origin ssh://[email protected]/[username]/[repository-name].git |
Set a repository's origin branch to SSH |
检查与比较
Command |
Description |
git log |
View changes |
git log --summary |
View changes (detailed) |
git diff [source branch] [target branch] |
Preview changes before merging |