Git 新建本地倉庫:
git init
複製代碼
Git 下載遠程代碼:
git clone + url地址
複製代碼
Git 查看當前分支修改內容狀態:
git status
複製代碼
Git 查看分支:
git branch -a
git branch
git branch -r
複製代碼
Git 重命名本地/遠程分支:
git branch -m <old_branch> <new_branch>
1. 修改本地分支名
git branch -m <old_branch> <new_branch>
2. 刪除要修改的遠程分支名
git push origin --delete <old_branch>
3. 將更名後的分支push到遠程
git push origin <new_branch>
複製代碼
Git 更新內容放入暫存區:
git add <filename>
git add .
複製代碼
Git 提交暫存區的內容:
git commit -m" the commit message "
git commit --amend
複製代碼
Git 拉取遠程代碼:
git pull origin <origin_branch>
git pull
複製代碼
Git 推送到遠程代碼:
git push origin <origin_branch>
複製代碼
Git 切換分支 / 建立並切換到本地新分支:
git checkout <branch_name>
git checkout -b <new_branch>
複製代碼
Git 放棄修改:
git checkout -- <filename>
git checkout .
複製代碼
Git 拉取遠程分支到本地:
1. 拉取遠程分支並更新本地分支(遠程分支拉取到本地後 git branch 不會顯示出來,因此須要進行 第二步 )
git pull
2.切換到遠程拉取到本地的分支上
git checkout <branch_name>
git checkout -b <local_branch> origin/<origin_branch>
複製代碼
Git 刪除本地分支:
git branch -d <branch_name>
git branch -D <branch_name>
複製代碼
Git 刪除遠程分支:
git push origin --delete <origin_branch>
git push origin :<origin_branch>
複製代碼
Git 查看日誌(日誌即分支的歷史合併):
git log
git log --oneline
git log -[length]
git log --name-status
git log --author yourname
git log --skip=[skip]
git log -p
複製代碼
Git 撤銷提交:
git reset --soft <commit id>
git revert HEAD
git reset --hard<commit id>
git revert commit
注意:reset 和 revert 的區別:revert 是用一次新的 commit 來回滾以前的 commit,reset 是直接刪除指定的 commit
複製代碼