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 |