0% found this document useful (0 votes)
10 views5 pages

Git Notes

This document provides a comprehensive overview of Git commands and their usage, including initializing a repository, managing branches, and handling commits. It also includes practice questions related to Git operations and conflict resolution. Key commands such as 'git stash', 'git merge', and 'git revert' are highlighted for their importance in version control workflows.

Uploaded by

windcustom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views5 pages

Git Notes

This document provides a comprehensive overview of Git commands and their usage, including initializing a repository, managing branches, and handling commits. It also includes practice questions related to Git operations and conflict resolution. Key commands such as 'git stash', 'git merge', and 'git revert' are highlighted for their importance in version control workflows.

Uploaded by

windcustom
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Git Notes

Git init 建立 git, 指定 folder 裡用,

Git clone <URL> 將 REMOTE REPO clone 落黎

Git add <file> 將指定 FILE 加去 STAGE, VSCODE 有 GUI 可簡單操作

Git add . 將所有 CHANGED FILE 加去 STAGE, VSCODE 有 GUI 可簡單操作

Git Status 查而家狀態, 會顯示咩 FILE CHANGE 左, 加左落 STAGE 未

Git commit -m <message> 建立改動點, VSCODE 有 GUI 做到

Git commit --amend 修改改動點的訊息, 改了後 PUSH 需要用 FORCE, commit hash 會

Git diff 查看改動內容, 限未 ADD 到 STAGE

Git branch 顯示現在分支

Git branch <branch_name> 建立分支

Git checkout <branch_name> 換分支

Git checkout -b <branch_name> 建立並換分支

Git switch <branch_name> 換分支(另一做法)

Git branch -d <branch_name> 刪除分支, 如-D 則 FORCE 刪除, 未 MERGE 時用

Git remote add origin <URL> 設定 remote repo 位置, 以後可以 origin 作為替代
URL, origin 是傳統不應改

Git push -u origin <branch_name> 將分支推上 remote 並作為預設

Git pull origin <branch_name> 將 remote 分支拉來

Git fetch 更新 remote 但不 merge, 主要用作比較差異


Git merge origin/main 將 remote 合併到 local

Git log 睇 commit history, 加—oneline 為簡潔版

Git show <commit> 顯示指定 commit

Git blame <file> 搵 LAST TOUCH 人, 冇用, sourcetree/vscode 有寫

Git revert <commit> 退回指定 commit, 用作 UNDO 修改, 不刪任何野, 安全

Git reset --soft HEAD~1 退回上一次 commit, 用於再 commit 或改 commit


message

Git reset --hard …… 勿做傻事

Git stash 暫時收起未 COMMIT 改動

Git stash list 睇下收起左 D 咩 stash

Git stash apply stash@{0} 將最新收起嘅 stash 放返出黎, 不刪除

Git stash pop 將最新收起嘅 stash 放返出黎, 刪除

Git checkout main

Git merge <branch_name> 合併用, 有衝突 VSCODE 會顯示, 可選留低邊一邊, 或兩邊都


留再人手執
Charlene’s practice questions:

GIT

1. You cloned a repo and made changes, but forgot to


create a branch. What do you do now?

I. Git stash

II. Git checkout -b new_branch

III. Git stash pop

2. You want to ignore a node_modules/ folder from being tracked.


What do you do?

I. Add it to .gitignore file

3. You need to delete a branch both locally and remotely. What


commands do you use?

I. Git branch -d <branch_name>

II. Git push origin --delete <branch_name>

4. You want to save your uncommitted changes temporarily and


switch branches. What do you use

I. Git stash

5. A merge conflict appears while pulling. How do you


resolve and complete the pull?

I. Git add <conflict_file>

II. Fix the conflict

III. Use vscode to merge will show the conflict point, more
easy to fix

6. You need to undo a git push to a shared branch. What steps do


you take?

I. Git revert <commit_hash>


II. Git push origin shared-branch

7. You need to start a new feature. What steps do you follow in


Git Flow?

I. Make a branch from develop in features/

II. Coding the new feature on this new branch

8. Explain git flow

I. Main, develop, feature/, hotfix/, release/

II. Main is the stable production version

III. Develop is the place for merge feature and get update
for members.

IV. Features/ is the place of branches that members are


using to code the new feature

V. Hotfix/ is the place to code the bug fix code

VI. Release/ is the version that prepare for production

9. Two developers create different feature branches (feature/a


and feature/b) and modify the same line in the same file. Both
merge into develop. What happens?

I. Conflict will happen. Choose the change from a or b, or


keep them both and resolve manually.

10. A hotfix is urgently applied directly on main, but you were


working on develop. What could go wrong when merging main
back to develop?

I. Hotfix may be replaced by develop

11. You tried to merge your feature into develop, but get a
"CONFLICT (content): Merge conflict in app.js". What do you
do?

I. Compare the app.js between feature and develop,


resolve it, add and commit it.

You might also like