Git經常使用命令 (持續更新)

生成SSH Key:git

ssh-keygen -t rsa -C "<email>"

設置:ssh

git config --global user.email "<email>"
git config --global user.name "<name>"

添加remote:code

git remote add <name> <path>
git pull <name> <branch> --rebase

使用pull <name> <branch> --rebase衝突後, 修改好衝突後 merge:rem

git add .
git pull --continue

查看改動:it

# 查看尚未暫存起來的變化內容
git diff
# 查看已經暫存起來的文件(staged)和上次提交時的的差別
git diff --cached
git diff --staged
# 顯示工做版本(working tree)和HAD的不一樣
git diff HEAD
# 當前目錄與另外一個分支的差異
git diff <branch>
# 比較上次提交和上上次提交
git diff HEAD^ HEAD

取消改動:email

# 放棄當前未暫存的改動
git checkout .
# 放棄git add .暫存後改動
git reset HEAD
# 放棄commit後但未push的改動,須要從新修改再push
git reset <commit_id>
# 放棄push到git後的改動
git reset --hard <commit_id>
git push origin HEAD --force

覆蓋上一條已經提交的commit:stream

git add .
git commit --amend
git push origin <branch> -f

刪除遠程ignored的文件:file

git rm -r --cached .
git add .
git commit -m "Removing all files in .gitignore"

拉取遠程分支並提交:rsa

git checkout -b <branch> <remote>/<branch>
git push --set-upstream origin <branch>

查看分支跟蹤狀況/設置新的跟蹤ssh-key

git branch -vv
git branch --set-upstream <branch> <remote>/<branch>
相關文章
相關標籤/搜索