Cheat sheet sa mga Git command
Ang Git ay tinatarak ang mga pagbabago sa iyong mga file bilang serye ng commits sa isang repository. Ang mga command na ito ay sumasakop sa araw-araw na workflow: paggawa ng repo, pag-save ng trabaho, branching, merging at pag-share sa isang remote. Buksan ang sheet na ito habang nag-aaral.
| Command | Ano ang ginagawa |
|---|---|
| git init | Create a new, empty Git repository in the current directory. |
| git clone | Download a remote repository and its full history to your machine. |
| git status | Show changed, staged and untracked files in the working tree. |
| git add | Stage changes (files) to be included in the next commit. |
| git commit | Record staged changes as a new commit with a message. |
| git log | Display the commit history of the repository. |
| git diff | Show unstaged or staged differences between states. |
| git branch | List, create or delete branches in the repository. |
| git checkout / switch | Switch branches or restore files (switch is the modern command). |
| git merge | Join another branch's history into the current branch. |
| git rebase | Reapply commits on top of another base commit, rewriting history. |
| git pull | Fetch from a remote and merge the changes into the current branch. |
| git push | Upload local commits to a remote repository. |
| git stash | Temporarily shelve uncommitted changes to reapply later. |
| git remote | Manage the set of remote repositories you track. |
Tala
- Ang karamihan ng command ay tumatanggap ng flags (tulad ng -m para sa message o -a para sa lahat); patakbuhin ang 'git help <command>' para sa buong listahan.
- Ang mga branch name ay mura at nakatapon — madalas na mag-commit sa isang feature branch, tapos i-merge sa main.
- Bago ang mga destructive command tulad ng rebase o reset, siguraduhing naka-commit o naka-stash ang iyong trabaho.
Mga madalas itanong
- Ano ang pagkakaiba ng merge at rebase?
- Ang merge ay pinagsasama ang mga history gamit ang isang bagong commit na may dalawang magulang. Ang rebase ay inuulit ang iyong mga commit sa ibabaw ng ibang branch, na gumagawa ng linear na history pero ini-rewrite ang commit IDs.
- Paano ko i-undo ang isang commit?
- Gamitin ang 'git revert <commit>' para magdagdag ng bagong commit na nag-uundo sa pagbabago (safe, nakabahagi ang history). Ang 'git reset' ay nag-rerewrite ng history at hindi dapat gamitin sa mga shared branch.
- Ano ang pagkakaiba ng git pull at git fetch?
- Ang fetch ay nagda-download ng mga commit at ref mula sa remote nang hindi tinatouch ang iyong working tree. Ang pull ay nagfa-fetch tapos mina-merge o rebase ang mga pagbabagong iyon sa iyong kasalukuyang branch.
- Kailan dapat gumamit ng git stash?
- Ang stash ay pansamantalang inilalagay sa gilid ang mga hindi pa na-commit na pagbabago para makapag-switch ng branch o makapag-pull nang malinis, at ibabalik sa 'git stash pop'.