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.
| Comandă | Ce face |
|---|---|
| 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. |
Note
- Majoritatea comenzilor acceptă flaguri (cum ar fi -m pentru mesaj sau -a pentru toate); rulează 'git help <comandă>' pentru lista completă.
- Numele de branch-uri sunt ieftine și de aruncat — fă commit des pe o ramură de funcționalitate, apoi îmbină în main.
- Înainte de comenzi distructive precum rebase sau reset, asigură-te că munca e commit-ită sau în stash.
Î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'.