github常用命令

一、安裝

sudo yum install git


二、常用步驟

# 初始化

git init  # 初始化

git remote add repo_name url # 添加遠程倉庫

git config --list  # 查看當前配

git remote -v  # 查看遠程倉庫


# 下拉代碼

git pull repo_name master # 下拉代碼

git clone http://url # 下拉代碼並自動添加遠程倉庫origin


# 提交代碼
git add .  
git commit -a # -m

git commit --allow-empty -m "Empty"    # 提交一個空提交,可以用於在新建分支後的首次提交

git push repo_name master              # 上傳代碼


# 創建分支

git branch branch_name exist_branch_name  # 創建分支

git checkout branch_name                  # 切換分支,令【head】指向【branch_name】

git checkout -b branch_name               # 創建並切換分支

git branch -m old_branch_name new_branch_name  # 重命名本地分支

git branch -d branch_name               # 刪除本地分支

git push origin :branch_name            # 刪除遠程分支


# 打標籤

git tag tag_name commit_id(前十位)        # 在本地打標籤

git tag                                   # 查看本地標籤

git show tag_name                         # 查看具體標籤

git push origin tag_name                  # 將本地指定標籤push到遠端

git push origin --tags                    # 將本地標籤push到遠端


# 合併分支

git merge branch_name                     # 合併branch_name分支到當前分支

git merge branch_name --no-ff             # 通常加--no-ff後綴


# 隱藏臨時修改,通常在切換branch過程中使用

git stash             # 隱藏臨時修改,切換branch之前使用

git stash pop         # 恢復/彈出臨時修改,在切換branch之後使用


# 合併多次提交

# 注意,rebase不要處理遠程庫,只用於本地操作,這樣比較安全

http://zerodie.github.io/blog/2012/01/19/git-rebase-i/

http://www.cnblogs.com/wujianlundao/archive/2012/07/30/2615873.html

git rebase -i previous_commit_id; 結合squash   # 修改之前的本地commit

git push origin branch_name --force            # 修改已經推送的遠程commit,在修改後強制推送


# 修改本地commit message

git commit --amend                       # 修改最近一次commit

git rebase -i previous_commit_id; 結合reword      # 修改之前的commit


參考

http://www.chenyudong.com/slide/git/#/

http://rogerdudler.github.io/git-guide/index.zh.html

http://yijiebuyi.com/blog/007269d04d5096d9397ce3daf9d84c48.html


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章