Ściąga z poleceń Git

Git śledzi zmiany w plikach jako serię commitów w repozytorium. Te polecenia obejmują codzienny przepływ: tworzenie repo, zapisywanie pracy, rozgałęzianie, scalanie i udostępnianie zdalnemu. Trzymaj tę ściągę otwartą podczas nauki.

Zaktualizowano:

PolecenieCo robi
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.

Uwagi

Częste pytania

Jaka jest różnica między merge a rebase?
Merge łączy historie nowym commitem mającym dwóch rodziców. Rebase odtwarza twoje commity na innym branchu, dając liniową historię, ale przepisuje ID commitów.
Jak cofnąć commit?
Użyj 'git revert <commit>', aby dodać nowy commit cofający zmianę (bezpieczne, wspólna historia). 'git reset' przepisuje historię i nie powinno się go używać na współdzielonych branchach.
Jaka jest różnica między git pull a git fetch?
Fetch pobiera commity i referencje z remote bez dotykania drzewa roboczego. Pull robi fetch, a potem scala lub robi rebase tych zmian do bieżącego brancha.
Kiedy używać git stash?
Stash tymczasowo odkłada niezcommitowane zmiany, by móc czysto przełączyć branch lub pobrać, a potem przywraca je przez 'git stash pop'.