Helaian tip arahan Git

Git menjejaki perubahan fail anda sebagai siri commit dalam repositori. Arahan ini meliputi alur kerja harian: mencipta repo, menyimpan kerja, bercabang, menggabung dan berkongsi dengan remote. Biarkan helaian ini terbuka semasa anda belajar.

Dikemas kini:

ArahanFungsinya
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.

Nota

Soalan lazim

Apakah bezanya merge dan rebase?
Merge menggabungkan sejarah dengan commit baharu yang mempunyai dua induk. Rebase memainkan semula commit anda di atas cawangan lain, menghasilkan sejarah linear tetapi menulis semula ID commit.
Bagaimana saya buat asal sesebuah commit?
Gunakan 'git revert <commit>' untuk menambah commit baharu yang membatalkan perubahan (selamat, sejarah dikongsi kekal). 'git reset' menulis semula sejarah dan tidak patut digunakan pada cawangan dikongsi.
Apakah bezanya git pull dan git fetch?
Fetch memuat turun commit dan rujukan dari remote tanpa menyentuh pokok kerja anda. Pull melakukan fetch kemudian menggabung atau me-rebase perubahan itu ke cawangan semasa anda.
Bila saya patut guna git stash?
Stash menyimpan sementara perubahan belum di-commit supaya anda boleh tukar cawangan atau pull dengan bersih, lalu memulihkannya dengan 'git stash pop'.