Peta dunia

 

EN: Read in English

Dunia 3: Alam Selari

Asas rebase

Anda akan belajar: alihkan branch anda ke atas main yang terkini.

Teks BM belum disemak oleh penutur asli.

Masalahnya

Log bercabang. main ada Make heading teal. about, tempat HEAD berada, ada Add about page dan Say what I like. Output terminal: $ git log --oneline --graph --all * 01bb13d (main) Make heading teal | * 203a91f (HEAD -> about) Say what I like | * a20da6c Add about page |/ * 270a76e Add style * a8feb63 Add day 1 page * 6d3a9b1 Add README

main dah bergerak semasa anda bina about. Anda nak kerja anda di atas main yang terkini. Tanpa merge commit.

Tengok

Dua commit about terangkat dan mendarat selepas Make heading teal. Sejarah jadi satu garis lurus.
6d3a9b1a8feb63270a76ea20da6c203a91f01bb13d

git rebase main main semula commit anda di atas main, satu demi satu. Macam alihkan kerja anda ke hujung barisan. Itulah rebase: Main semula commit anda di atas branch lain. Ia jadi commit baru. (asas semula).

Cuba

Anda di about. Rebase ke atas main.

6d3a9b1a8feb63270a76ea20da6c203a91f01bb13d

Tengok

Sebelum rebase, dua commit about ada sepasang hash pendek. Selepas itu, mesej yang sama ada hash baru. Output terminal: $ git log --oneline -n 2 203a91f (HEAD -> about) Say what I like a20da6c Add about page $ git rebase main Successfully rebased and updated refs/heads/about. $ git log --oneline -n 2 63ec942 (HEAD -> about) Say what I like 0e8659c Add about page

Tengok id itu. Mesej sama, hash baru! Rebase buat salinan baru commit anda.

Teka

about kini betul-betul di atas main. Anda merge about ke main. Apa jadi?

Pilih satu jawapan.

Cuba

Bawa about masuk ke main. Perhatikan fast-forward!

6d3a9b1a8feb63270a76e01bb13d0e8659c63ec942

Anda berjaya!

Kini anda boleh rebase branch ke atas main yang terkini.

Nak tahu lebih (pilihan)

Rebase pun boleh berhenti kerana konflik. Baiki fail itu dan git add. Kemudian jalankan git rebase --continue. Ubah fikiran? git rebase --abort kembalikan semuanya. Penanda bawah menamakan commit yang sedang dimain semula.

git rebase main berhenti: CONFLICT dalam index.html, tak dapat apply Add cake day. git status kata rebase sedang berjalan dan senaraikan langkahnya. Output terminal: $ git rebase main Auto-merging index.html CONFLICT (content): Merge conflict in index.html error: could not apply 0c66136... Add cake day hint: Resolve all conflicts manually, mark them as resolved with hint: "git add/rm <conflicted_files>", then run "git rebase --continue". hint: You can instead skip this commit: run "git rebase --skip". hint: To abort and get back to the state before "git rebase", run "git rebase --abort". hint: Disable this message with "git config set advice.mergeConflict false" Could not apply 0c66136... # Add cake day $ git status interactive rebase in progress; onto 013a957 Last command done (1 command done): pick 0c66136 # Add cake day No commands remaining. You are currently rebasing branch 'cake' on '013a957'. (fix conflicts and then run "git rebase --continue") (use "git rebase --skip" to skip this patch) (use "git rebase --abort" to check out the original branch) Unmerged paths: (use "git restore --staged <file>..." to unstage) (use "git add <file>..." to mark resolution) both modified: index.html no changes added to commit (use "git add" and/or "git commit -a")