Κάρτα αναφοράς εντολών Git

Το Git παρακολουθεί τις αλλαγές στα αρχεία σας ως μια σειρά commits σε ένα αποθετήριο. Αυτές οι εντολές καλύπτουν την καθημερινή ροή: δημιουργία αποθετηρίου, αποθήκευση εργασίας, διακλάδωση, συγχώνευση και κοινοποίηση με απομακρυσμένο. Κρατήστε την κάρτα ανοιχτή όσο μαθαίνετε.

Ενημερώθηκε:

ΕντολήΤι κάνει
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.

Σημειώσεις

Συχνές ερωτήσεις

Ποια είναι η διαφορά μεταξύ merge και rebase;
Το merge συνδυάζει ιστορικά με ένα νέο commit που έχει δύο γονείς. Το rebase αναπαράγει τα commits σου πάνω σε άλλο κλάδο, δίνοντας γραμμικό ιστορικό αλλά ξαναγράφοντας τα ID των commits.
Πώς αναιρώ ένα commit;
Χρησιμοποίησε το 'git revert <commit>' για να προσθέσεις ένα νέο commit που αναιρεί την αλλαγή (ασφαλές, διατηρεί κοινό ιστορικό). Το 'git reset' ξαναγράφει το ιστορικό και δεν πρέπει να χρησιμοποιείται σε κοινόχρηστους κλάδους.
Ποια η διαφορά μεταξύ git pull και git fetch;
Το fetch κατεβάζει commits και αναφορές από απομακρυσμένο χωρίς να αγγίζει το δέντρο εργασίας σου. Το pull κάνει fetch και μετά συγχωνεύει ή κάνει rebase αυτές τις αλλαγές στον τρέχοντα κλάδο σου.
Πότε πρέπει να χρησιμοποιώ το git stash;
Το stash βάζει προσωρινά στην άκρη μη αποθηκευμένες αλλαγές ώστε να αλλάξεις κλάδο ή να κάνεις καθαρό pull, και τις επαναφέρεις με 'git stash pop'.