https://slides.com/dmoon/git/live
未保存的變更
已保存的記錄 (commit)
Timeline
# set your default info
$ git config --global user.email "name@mail.com"
$ git config --global user.name "userName"
# set info of current git project
$ git config user.name "userName"
# list config
$ git config -l
重要的是記得有哪些功能!
忘了這邊查 -> Git 命令快速參考
# init git in your project directory
$ git init
建立 .gitignore 檔案
# 輸入你想忽略的檔案路徑名稱
# ignore ./test.html
test.html
# ignore whole ignore_dir directory
ignore_dir/
# ignore all css file
*.css
# add file
$ git add fileName
# add all files
$ git add .
# check added files
$ git status
# untrack & delete tracked file
$ git rm fileName
# only untrack tracked file
$ git rm --cached fileName
# check current status
$ git status
# commit added files
$ git commit
# commit with message
$ git commit -m "Write some message here"
# show git commit histories
$ git log
$ git commit --amend
# diffs between tracked but unStaged files and HEAD
$ git diff
# diffs between staged files and HEAD
$ git diff --cached
# src and dest can be commitID or branch
$ git diff <src> <dest>
# 暫存當前工作目錄
$ git stash
# show stash list
$ git stash list
# 還原暫存工作目錄
$ git stash pop
# delete last stash
$ git stash drop
# clear all stash
$ git stash clear
# switch branch
$ git checkout branchName
# checkout old version commit
$ git checkout <commitID>
# reset file to last commit
$ git reset HEAD fileName
# reset all files to last commit
$ git reset HEAD
# reset with option
$ git reset --option HEAD
Reset Option | Work Directory | Staging Area | HEAD |
---|---|---|---|
soft | X | X | O |
mixed (default) | X | O | O |
hard | O | O | O |
O:do reset
X:not reset
# list all branches
$ git branch
# create a new branch
$ git branch <branchName>
# switch to another branch
$ git checkout <branchName>
# create a new branch and switch to it
$ git checkout -b <branchName>
# delete the branch
$ git branch -d <branchName>
# merge a <branchName> into your active branch
$ git merge <branchName>
# clone a repo
$ git clone <srcRepoPath> <destDirName>
# connect local repository to a remote repository
$ git remote add <remoteRepoName> <remoteRepoPath>
# list all connected remote repository
$ git remote -v
# send changes to the remote branch
# of your remote repository
$ git push <remoteRepoName> <remoteBranchName>
# fetch the latest history from the server
$ git fetch
# remoteRepoName default origin
# remoteBranchName default master
$ fetch result is in FETCH_HEAD
$ git fetch <remoteRepoName> <remoteBranchName>
# fetch and merge remoteBranch to current branch
$ git pull <remoteRepo> <remoteBranch>
# show file history
$ git blame <fileName>