1. 關於git bash常用指令 推薦博客:
Learn Version Control with Git for Free
2. 常用指令:
git config --global user.name "名字"
git config --global user.email "郵箱"
git status 查看當前狀態
git init 初始化本地倉庫
git add “filename”
git commit –m “注釋”
git log
git branch 查看分支
git branch a 創建分支a
git checkout a 切換到a分支
git merge a 將分支a合並到當前分支
git branch –d a 刪除分支a
git branch –D a 強制刪除分支a
git push origin master
git pull origin master 把遠端origin的master分支的最新版本拉取到本地,自動merge
git fetch origin master 把遠端origin的master分支的最新版本拉取到本地,不merge,較安全
git clone https://github.com/... 克隆遠程倉庫
git remote add origin https://github.com/... 關聯遠程倉庫
git reset --hard 版本號 回滾到特定版本
git push -f origin master 將本地的當前版本強制提交到遠程倉庫中
注意:在我們向遠程倉庫提交代碼的時候,一定要先進行pull操作,再進行push操作,防止本地倉庫與遠程倉庫不同步導致沖突的問題。
These are common Git commands used in various situations:
start a working area (see also: git help tutorial) |
|
clone |
Clone a repository into a new directory |
init |
Create an empty Git repository or reinitialize an existing one |
work on the current change (see also: git help everyday) |
|
add |
Add file contents to the index |
mv |
Move or rename a file, a directory, or a symlink |
reset |
Reset current HEAD to the specified state |
rm |
Remove files from the working tree and from the index |
examine the history and state (see also: git help revisions) |
|
bisect |
Use binary search to find the commit that introduced a bug |
grep |
Print lines matching a pattern |
log |
Show commit logs |
show |
Show various types of objects |
status |
Show the working tree status |
grow, mark and tweak your common history |
|
branch |
List, create, or delete branches |
checkout |
Switch branches or restore working tree files |
commit |
Record changes to the repository |
diff |
Show changes between commits, commit and working tree, etc |
merge |
Join two or more development histories together |
rebase |
Reapply commits on top of another base tip |
tag |
Create, list, delete or verify a tag object signed with GPG |
collaborate (see also: git help workflows) |
|
fetch |
Download objects and refs from another repository |
pull |
Fetch from and integrate with another repository or a local branch |
push |
Update remote refs along with associated objects |