software
Make some changes §
- git clone 網址
- Add the new files
- git add
- git commit -m”…”
- git push
Branch §
- List all branch
git branch -a
- Revert commit
git reset HEAD^
- Checkout to remote branch with detached HEAD
git checkout -t branch_name
- Instruction - git branch naming
- git branch
- git branch your new branch name
- git checkout branch name
- purpose
- branches allow us to work on different versions of the same files in parallel.
- common types of the branch
- feature branch, bugfix branch
- develop branch
- release brance
- hotfix branch
- main branch
Before merge the branch §
- git diff branch one .. branch two
- to see the difference between two branches
- git branch —merged
- check whether the current branch is merged with master
- if the branch has merged, we can delete it.
Merge the branch §
- git merge branch name
- fast-forward merged (舊版本與新版本的branch可以直接合併)
- merge the current branch with the branch name
- Merge conflicts (不同的新版本合併可能會發生衝突)
- edit the file (merge後git會警告, 並自動產生註解, 要編輯文件, 選擇要捨去與保留的部份)
- git commit
After merge §
- git branch -d branch name
- delete the branch that has merged with master
Branch management strategy §
- Githubflow
- long-running branch: main
- short-lived: feature branches, bugfix branches
- Gitflow
- more structure and rules
- long-running branches : main + develop
- short-lived: feature, release, hotfixes branches
- Determine the branching model
- consider project, release cycle, team
Fetch §
- git fetch
- 可以取得遠端數據庫的最新歷史記錄, 取得的提交會導入在自動建立的分支中, 並可以切換這個名為 FETCH_HEAD 的分支
Pull §
- git pull = git pull + git merge FETCH_HEAD
Log §
Skip certain changed file at local repo §
- To prevent a tracked but changed file from appearing as changed in the Git status, use
- To undo and start showing it as changed again: