Fișă cu comenzi Git

Git urmărește modificările fișierelor ca o serie de commit-uri într-un depozit. Aceste comenzi acoperă fluxul zilnic: crearea unui repo, salvarea muncii, ramificarea, îmbinarea și partajarea cu un depozit la distanță. Păstrează această fișă deschisă în timp ce înveți.

Actualizat:

ComandăCe face
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.

Note

Întrebări frecvente

Care este diferența între merge și rebase?
Merge combină istoricele printr-un commit nou care are doi părinți. Rebase rejouează commit-urile tale deasupra altei ramuri, producând un istoric liniar dar rescriind ID-urile commit-urilor.
Cum anulez un commit?
Folosește 'git revert <commit>' pentru a adăuga un commit nou care anulează modificarea (sigur, păstrează istoricul comun). 'git reset' rescrie istoricul și nu trebuie folosit pe ramuri partajate.
Care e diferența între git pull și git fetch?
Fetch descarcă commit-uri și referințe de la un depozit la distanță fără să atingă arborele de lucru. Pull face fetch apoi îmbină sau face rebase acelor modificări în ramura curentă.
Când ar trebui să folosesc git stash?
Stash pune deoparte temporar modificările necomitate ca să poți schimba ramura sau trage curat, apoi le restaurezi cu 'git stash pop'.