Git-komentojen pikaopas

Git seuraa tiedostojen muutoksia commit-sarjana repositoriossa. Nämä komennot kattavat päivittäisen työnkulun: repon aloitus, työn tallennus, haaraaminen, yhdistäminen ja jakaminen etän kanssa. Pidä tämä opas auki opiskellessasi.

Päivitetty:

KomentoMitä tekee
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.

Huomautukset

Usein kysytyt kysymykset

Mikä on erona merge- ja rebase-komentojen välillä?
Merge yhdistää historiat uudella commitilla, jolla on kaksi vanhempaa. Rebase toistaa commitisi toisen haaran päällä, mikä tuottaa lineaarisen historian mutta kirjoittaa commit-tunnukset uudelleen.
Miten peruutan commitin?
Käytä 'git revert <commit>' lisätäksesi uuden commitin, joka kumoaa muutoksen (turvallinen, jaettu historia säilyy). 'git reset' kirjoittaa historian uudelleen eikä sitä pidä käyttää jaetuilla haaroilla.
Mikä on erona git pull- ja git fetch-komentojen välillä?
Fetch lataa commitit ja viitteet etän ilman että koskettaa työpuuta. Pull tekee haun ja yhdistää tai rebaseaa muutokset nykyiseen haaraasi.
Milloin git stash kannattaa käyttää?
Stash laittaa commitoimattomat muutokset väliaikaisesti syrjään, jotta voit vaihtaa haaraa tai hakea puhtaasti, ja palauttaa ne myöhemmin komennolla 'git stash pop'.