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.

Na-update:

CommandAno ang ginagawa
git initCreate a new, empty Git repository in the current directory.
git cloneDownload a remote repository and its full history to your machine.
git statusShow changed, staged and untracked files in the working tree.
git addStage changes (files) to be included in the next commit.
git commitRecord staged changes as a new commit with a message.
git logDisplay the commit history of the repository.
git diffShow unstaged or staged differences between states.
git branchList, create or delete branches in the repository.
git checkout / switchSwitch branches or restore files (switch is the modern command).
git mergeJoin another branch's history into the current branch.
git rebaseReapply commits on top of another base commit, rewriting history.
git pullFetch from a remote and merge the changes into the current branch.
git pushUpload local commits to a remote repository.
git stashTemporarily shelve uncommitted changes to reapply later.
git remoteManage the set of remote repositories you track.

Tala

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'.