Ketika memutuskan untuk menggunakan alat ini atau itu dalam proyeknya sendiri, insinyur tidak hanya harus mempelajari dokumentasi pendukung, tetapi juga melakukan serangkaian percobaan untuk menghindari masalah potensial di masa depan. Jika kita berbicara tentang kebijakan CM, yang dirancang untuk jangka panjang, harga kesalahan pilihan menjadi cukup tinggi.
Tujuan dari makalah ini adalah untuk berlatih alat manajemen subtree Git .
Dimulai dengan revisi 1.7.11 , repositori upstream Git , di direktori contrib / subtree , berisi alat untuk mengotomatisasi pekerjaan dengan subtree .
Layanan git-subtree (1) sebenarnya merupakan add-on yang berguna yang menggunakan fungsi git-read-tree (1) dan git-write-tree (1) . Oleh karena itu, tautan di perintah git-subtree (1) add / pull / push :
git subtree add --prefix=<subdir> <remote> <ref>
bisa berupa nama cabang atau nama tag dari repositori jarak jauh.
Selain itu, jika Anda menambahkan repositori jarak jauh ke file konfigurasi repositori .git / config lokal sebelumnya, menggunakan perintah:
bash-4.4$ git remote add build-system ../../remote/build-system.git
di mana build-system adalah nama repositori jarak jauh ../../remote/build-system.git , maka di masa depan, saat menggunakan perintah git-subtree (1) add / pull / push , kita bisa merujuk ke upstream remote / repository build-system.git dengan nama.
Pada saat ini, git-subtree (1) secara praktis tidak berkembang, tetapi hanya terus diperbarui untuk tingkat perkembangan saat ini dari proyek Git .
Namun, git-subtree (1) adalah alat yang paling populer dan kuat untuk bekerja dengan subtree.
Lingkungan uji
Dalam artikel git-subrepo (1) sebelumnya , kami menggunakan struktur direktori sederhana dengan repositori uji untuk menunjukkan bagaimana fungsi bekerja dalam praktik. Sekarang kami mereproduksi lingkungan berikut:
bash-4.4$ vim _init.sh
Di sini
pemilik | - | direktori kerja penulis proyek; |
jauh | - | Direktori yang mewakili server penulis proyek, di mana repositori hulu dari platform proyek utama.git dan sub-proyek build-system.git berada ; |
pengguna | - | Direktori kerja pengguna atau anggota tim pengembangan. |
Sebagai tujuan mempelajari kemampuan git-subtree (1), kami akan mempertimbangkan semua tugas yang sama dengan yang kami bicarakan dalam artikel Git Subrepo , tetapi dengan mempertimbangkan perbedaan antara kedua alat tersebut.
Hubungkan subtree
Ingat keadaan repositori remote / platform.git saat ini :
bash-4.4$ bash-4.4$ cd owner/platform/ bash-4.4$ git log commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d (HEAD -> master, origin/master) Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
dan hubungkan cabang master remote repositori / build-system.git ke direktori build-system:
bash-4.4$ bash-4.4$ git subtree add --prefix=build-system ../../remote/build-system.git/ master git fetch ../../remote/build-system.git/ master warning: no common commits remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From ../../remote/build-system * branch master -> FETCH_HEAD Added dir 'build-system' bash-4.4$
Pertimbangkan keadaan baru dari salinan lokal repositori remote / platform.git :
bash-4.4$ bash-4.4$ git log --graph * commit 47905bcb80be6f7cb3030513986fad4df548f812 (HEAD -> master) |\ Merge: 7fad4be 783c6d5 | | Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d (origin/master) Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
Di sini Anda harus memperhatikan pesan bahwa git-subtree (1) menambahkan perintah ke kiri. Bahkan, menggunakan perintah ini, kami menempatkan perbedaan dalam repositori platform :
bash-4.4$ bash-4.4$ git diff 7fad4becbd13258216fb95cbe9d987dd33f0be6d 47905bcb80be6f7cb3030513986fad4df548f812 diff --git a/build-system/README b/build-system/README new file mode 100644 index 0000000..73a41c7 --- /dev/null +++ b/build-system/README @@ -0,0 +1,3 @@ + +[master] build-system 1.0.0 + bash-4.4$
Lebih lanjut, ketika sejarah perubahan sedikit lebih jauh, kami akan mempelajari rincian menghubungkan subtrees secara lebih rinci, dan sekarang kami akan menempatkan perubahan kami di remote / platform repositori upstream.
bash-4.4$ bash-4.4$ git push Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 582 bytes | 582.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git 7fad4be..47905bc master -> master bash-4.4$
dan lihat lagi pada git-subtree (1) tambahkan command post:
Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' git-subtree-dir: build-system git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 git-subtree-repo: ../../remote/build-system.git/ git-subtree-ref: master
Pesan-pesan ini berguna sehingga, jika perlu, Anda dapat menemukan riwayat koneksi dan status subtree saat ini. Perintah git-subtree (1) yang asli tidak menambahkan dua baris terakhir dari pesan. Kami sedikit memodifikasi utilitas ini untuk mempermudah mencari informasi tentang kapan dan dari cabang repositori jarak jauh mana subtree dari proyek kami dibuat.
Anda bisa mendapatkan file lengkap perubahan kami sebagai berikut:
bash-4.4$ bash-4.4$ git clone https://github.com/radix-platform/git.git bash-4.4$ cd git bash-4.4$ git checkout git-subtree-2.19.1 bash-4.4$ git diff v2.19.1 > ../git-subtree-2.19.1.patch bash-4.4$
Untuk membuat contoh kami lebih realistis, kami akan membuat perubahan pada repositori remote / build-system.git :
bash-4.4$ bash-4.4$ cd owner/build-system/ bash-4.4$ vim README bash-4.4$ cat README [master] build-system 1.0.1 bash-4.4$
Simpan perubahan ini:
bash-4.4$ bash-4.4$ git add README bash-4.4$ git commit -m "update build-system version to 1.0.1" [master e5c5446] update build-system version to 1.0.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
dan meneruskannya ke remote / build-system.git repositori hulu:
bash-4.4$ bash-4.4$ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 274 bytes | 274.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git 783c6d5..e5c5446 master -> master bash-4.4$
Jadi, revisi repositori build-system telah berubah dari 783c6d5 menjadi e5c5446:
bash-4.4$ bash-4.4$ git log commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 (HEAD -> master, origin/master) Author: user <___@_______> Date: Thu Nov 1 20:26:52 2018 +0300 update build-system version to 1.0.1 commit 783c6d5af1100e9665f930c818c861ff011bed19 Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init build-system master 1.0.0 bash-4.4$
Ingat keadaan ini dan lanjutkan bekerja dengan repositori wadah / platform.git .
Mengambil perubahan dari repositori subtree hulu
Katakanlah kita masih tidak tahu tentang perubahan dalam repositori hulu subtree dan sedang berupaya meningkatkan kode platform :
bash-4.4$ bash-4.4$ cd owner/platform/ bash-4.4$ vim README bash-4.4$ cat README [master] platform 1.0.1 bash-4.4$ bash-4.4$ git add README bash-4.4$ git commit -m "update platform version to 1.0.1" [master 442c9e9] update platform version to 1.0.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ bash-4.4$ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 306 bytes | 306.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/platform.git 47905bc..442c9e9 master -> master bash-4.4$
Sebagai hasil dari pekerjaan kami, kami mendapat status repositori remote / platform.git berikut :
bash-4.4$ bash-4.4$ git log --graph * commit 442c9e94c9890032fb2f3123661345d465e2849f (HEAD -> master, origin/master) | Author: user <___@_______> | Date: Thu Nov 1 20:41:40 2018 +0300 | | update platform version to 1.0.1 | * commit 47905bcb80be6f7cb3030513986fad4df548f812 |\ Merge: 7fad4be 783c6d5 | | Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
Sekarang, akan menyenangkan untuk mengetahui apa yang terjadi di repositori hulu dari subtree sistem-bangun ketika kami sedang bekerja untuk meningkatkan kode dalam repositori utama proyek kami. Gulir melalui sub pohon pertama dengan perintah git subtree --list :
bash-4.4$ bash-4.4$ git subtree --list build-system ../../remote/build-system.git/ branch master HEAD bash-4.4$
Perintah ini, dalam format sederhana, menyajikan direktori subtree, URL repositori upstream subtree, jenis tautan (cabang atau tag), nama tautan, serta revisi cabang atau tag repositori yang ditentukan, yang kodenya kami masukkan ke subtree kami. Namun, kami ingat bahwa pengembangan sub - proyek sistem pembangunan telah berjalan maju dan menunjuk ke kepala cabang utama tidak lagi valid. Sebaliknya, ini adalah pesan tentang apa yang ingin kita miliki di repositori kita, dan bukan keadaan sebenarnya.
Untuk mengetahui berapa banyak kode telah berkembang dalam repositori upstream dari subtree, kita juga perlu menggulir melalui subpohon, tetapi menggunakan opsi -d :
bash-4.4$ bash-4.4$ git subtree -d --list Looking for externals... Commit: 47905bcb80be6f7cb3030513986fad4df548f812 build-system ../../remote/build-system.git/ branch master HEAD The 'build-system' subtree seems not updated: original revision: 783c6d5af1100e9665f930c818c861ff011bed19 remote revision: e5c5446967599065dc02a269d8fcfc2c1d3c4f65 You can update 'build-system' subtree by following command: git subtree pull --prefix=build-system ../../remote/build-system.git/ master bash-4.4$
Sekarang, hasilnya menunjukkan bahwa ketika kami sedang mengerjakan kode repositori utama, cabang master dari repositori hulu dari subtree sistem bangun berjalan. Selain itu, perintah git subtree -d --list mengeluarkan petunjuk bahwa kita bisa mendapatkan perubahan pada repositori subtree hulu sebagai berikut:
bash-4.4$ bash-4.4$ git subtree pull --prefix=build-system ../../remote/build-system.git/ master remote: Enumerating objects: 5, done. remote: Counting objects: 100% (5/5), done. remote: Total 3 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From ../../remote/build-system * branch master -> FETCH_HEAD hint: Waiting for your editor to close the file...
perintah ini, karena kami tidak menentukan -m "melakukan pesan" , membuka editor dengan teks pesan:
Gabungkan komit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65'
# Silakan masukkan pesan komit untuk menjelaskan mengapa penggabungan ini diperlukan,
# khususnya jika menggabungkan upstream yang diperbarui ke cabang topik.
#
# Baris yang dimulai dengan '#' akan diabaikan, dan pesan kosong dibatalkan
# komit.
Ganti teks ini dengan yang lebih informatif:
Tarik perubahan dari master repositori hulu build-system.git:
Gabungkan komit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65'
Setelah menyimpan pesan ini dan menutup editor, kami mendapatkan hasil sebagai berikut:
Merge made by the 'recursive' strategy. build-system/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
Yaitu, kami menerima perubahan remote repositori / build-system.git upstream dan menyimpannya di subtree build-system dari salinan lokal remote repositori utama / platform.git .
Periksa status repositori lokal:
bash-4.4$ bash-4.4$ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean bash-4.4$
Agar pengguna lain dari proyek dapat memperoleh perubahan ini, kita perlu menempatkannya di remote / platform repositori upstream.
bash-4.4$ bash-4.4$ git push Enumerating objects: 9, done. Counting objects: 100% (8/8), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 583 bytes | 583.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git 442c9e9..ea52eab master -> master bash-4.4$
Mari kita lihat apa isi repositori platform sekarang, dan juga repositori remote / platform.git :
bash-4.4$ bash-4.4$ git log --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 | | * | commit 47905bcb80be6f7cb3030513986fad4df548f812 |\ \ Merge: 7fad4be 783c6d5 | |/ Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
Kita melihat bahwa keadaan awal
repositori remote / build-system.git , pada saat itu terhubung sebagai subtree platform, adalah
783c6d5af1100e9665f930c818c861ff011bed19 . Namun, ketika kami sedang mengerjakan kode di repositori
platform , keadaan repositori berubah dan menjadi sama dengan
e5c5446967599065dc02a269d8fcfc2c1d3c4f65 .
Keadaan awal sistem build ( 783c6d5af1100e9665f930c818c861ff011bed19 ) sudah ada dalam sejarah repositori platform ketika berada di 442c9e94c9890032fb2f3123661345d465e2849f . Oleh karena itu, kita perlu mengambil status platform di 442c9e94c9890032fb2f3123661345d465e2849f dan status sistem bangun di e5c5446967599065dc02a269d8fcfc2c1d3c4f65 , menghitung perbedaan di antara mereka, dan membuat perbedaan di antara cabang yang dihasilkan.
Ini adalah operasi standar penggabungan cabang, esensi yang dapat diungkapkan oleh rumus
p[n] = p[n-1] + diff(p[n-1], b[n])
dimana
p[n] = ea52eabd5910159efabd80adcf522f22bf6a2af2, p[n-1] = 442c9e94c9890032fb2f3123661345d465e2849f, b[n] = e5c5446967599065dc02a269d8fcfc2c1d3c4f65.
Di sini p bertindak sebagai cabang master, dan b , memainkan peran cabang yang sebelumnya dipisahkan dari master untuk membuat fungsionalitas baru.
Pertimbangkan lagi pesan bahwa utilitas git-subtree (1) disiapkan untuk kita selama pelaksanaan perintah git-subtree-pull :
git subtree pull --prefix=build-system ../../remote/build-system.git/ master
Gabungkan komit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65'
# Silakan masukkan pesan komit untuk menjelaskan mengapa penggabungan ini diperlukan,
# khususnya jika menggabungkan upstream yang diperbarui ke cabang topik.
#
# Baris yang dimulai dengan '#' akan diabaikan, dan pesan kosong dibatalkan
# komit.
Pesan ini mengandung informasi penting bagi kami, yaitu kondisinya
b[n] = e5c5446967599065dc02a269d8fcfc2c1d3c4f65
di mana cabang master dari repositori remote / build-system.git terletak sebelum " mengunggah " ke cabang master dari repositori platform .
Tentu saja, tidaklah mudah untuk secara manual mengeksekusi pesan komit ketika mengeksekusi perintah git-subtree-pull , namun, cara lain untuk memberikan kita status
b[n] = e5c5446967599065dc02a269d8fcfc2c1d3c4f65
utilitas git-subtree (1) , dalam hal ini, sama sekali tidak ada.
Jika kita menggunakan kontrol -m
git subtree pill -m "Our own message" ...
maka kita akan kehilangan nilai status b [n] dan, komentar kita tidak akan informatif, dan, oleh karena itu, sama sekali tidak berguna.
Perlu dicatat bahwa setelah status cabang master dari repositori build-system telah berpindah dari titik mount asli 47905bcb80be6f7cb3030513986fad4df548f812 , kami akan selalu menerima pemberitahuan tentang perubahan di remote / build-system.git sambil melihat daftar subkontraktor yang terhubung. Dengan kata lain, menggunakan opsi -d dalam sebuah perintah:
git subtree -d --list
akan selalu menghasilkan pesan yang mirip dengan yang berikut:
bash-4.4$ bash-4.4$ git subtree -d --list Looking for externals... Commit: 47905bcb80be6f7cb3030513986fad4df548f812 build-system ../../remote/build-system.git/ branch master HEAD The 'build-system' subtree seems not updated: original revision: 783c6d5af1100e9665f930c818c861ff011bed19 remote revision: e5c5446967599065dc02a269d8fcfc2c1d3c4f65 You can update 'build-system' subtree by following command: git subtree pull --prefix=build-system ../../remote/build-system.git/ master bash-4.4$
Ini akan terjadi karena semua informasi tentang subtree yang terhubung ada dalam pesan yang menyertai 47905bcb80be6f7cb3030513986fad4df548f812 komit:
bash-4.4$ bash-4.4$ git show 47905bcb80be6f7cb3030513986fad4df548f812 commit 47905bcb80be6f7cb3030513986fad4df548f812 Merge: 7fad4be 783c6d5 Author: user <___@_______> Date: Thu Nov 1 20:20:20 2018 +0300 Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' git-subtree-dir: build-system git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 git-subtree-repo: ../../remote/build-system.git/ git-subtree-ref: master diff --cc build-system/README index 0000000,0000000..73a41c7 new file mode 100644 --- /dev/null +++ b/build-system/README @@@ -1,0 -1,0 +1,3 @@@ ++ ++[master] build-system 1.0.0 ++ bash-4.4$
dan tidak ada repositori lain dari informasi ini.
Satu-satunya hal adalah bahwa sekarang setelah setiap pembaruan cabang master dari repositori remote / build-system.git , di sisi platform , ketika menjalankan perintah
git subtree -d --list
hanya nilai string yang akan berubah
remote revision: e5c5446967599065dc02a269d8fcfc2c1d3c4f65
dan kita sendiri perlu mengambil keputusan tentang apakah kita memerlukan perubahan baru pada subtree sistem bangun atau, pada saat ini, tidak diperlukan.
Namun, tidak akan sulit bagi kita untuk mengeksekusi perintah pull sesering yang kita perlukan, karena jika repositori remote / build-system.git tidak memiliki perubahan aktual, perintah:
git subtree pull --prefix=build-system ../../remote/build-system.git/ master
akan memberikan pesan yang memadai:
bash-4.4$ bash-4.4$ git subtree pull --prefix=build-system ../../remote/build-system.git/ master From ../../remote/build-system * branch master -> FETCH_HEAD Already up to date. bash-4.4$
Mendapatkan kode oleh pengguna
Sekarang semua pengguna repositori remote / platform.git bisa mendapatkan source tree yang sepenuhnya dikonfigurasi dengan perintah git-pull (1) tunggal:
bash-4.4$ bash-4.4$ cd user/platform/ bash-4.4$ bash-4.4$ git pull remote: Enumerating objects: 15, done. remote: Counting objects: 100% (15/15), done. remote: Compressing objects: 100% (8/8), done. remote: Total 13 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (13/13), done. From ../../remote/platform 7fad4be..ea52eab master -> origin/master Updating 7fad4be..ea52eab Fast-forward README | 2 +- build-system/README | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 build-system/README bash-4.4$
Selain itu, pengguna akan dapat melacak sejarah pengembangan tidak hanya repositori utama proyek, tetapi juga dari semua subtree-nya:
bash-4.4$ bash-4.4$ git log -3 --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master, origin/HEAD) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$
Mengirim perubahan subtree ke repositori hulu
Ingat keadaan file, serta repositori platform itu sendiri:
bash-4.4$ bash-4.4$ git log -3 --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master, origin/HEAD) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$
Kami akan membuat perubahan pada subtree sistem bangun . Untuk melakukan ini, edit file platform / build-system / README :
bash-4.4$ bash-4.4$ cd owner/platform/ bash-4.4$ bash-4.4$ vim build-system/README bash-4.4$ cat build-system/README [master] build-system 1.0.2 bash-4.4$ bash-4.4$ git add build-system/README bash-4.4$ git commit -m "build-system is updated to version 1.0.2 from platform side" [master abaa2c5] build-system is updated to version 1.0.2 from platform side 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
Tetapi kami tidak akan mencatat perubahan ini di repositori platform asal / master. Artinya, kita tidak akan menjalankan perintah git-push (1) , tetapi menjalankan git-subtree-push langsung ke asal repositori remote / build-system.git :
bash-4.4$ bash-4.4$ git subtree push --prefix=build-system ../../remote/build-system.git/ master git push using: ../../remote/build-system.git/ master Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 290 bytes | 290.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git/ e5c5446..0673142 0673142942ccf53514a276e855a98514952bb713 -> master bash-4.4$
Gulir melintasi subpohon dan pastikan bahwa cabang-cabang master HEAD dari repositori remote / build-system.git yang asli melanjutkan:
bash-4.4$ bash-4.4$ git subtree -d --list Looking for externals... Commit: 47905bcb80be6f7cb3030513986fad4df548f812 build-system ../../remote/build-system.git/ branch master HEAD The 'build-system' subtree seems not updated: original revision: 783c6d5af1100e9665f930c818c861ff011bed19 remote revision: 0673142942ccf53514a276e855a98514952bb713 You can update 'build-system' subtree by following command: git subtree pull --prefix=build-system ../../remote/build-system.git/ master bash-4.4$
Selain itu, mari kita lihat keadaan salinan lokal repositori platform , mengingat komit terakhir belum ditetapkan oleh kami di repositori hulu:
bash-4.4$ bash-4.4$ git log -4 --graph * commit abaa2c5edd49dd0cf395c99877b4711d0170af37 (HEAD -> master) | Author: user <___@_______> | Date: Thu Nov 1 21:48:40 2018 +0300 | | build-system is updated to version 1.0.2 from platform side | * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (origin/master) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$
Cara yang benar untuk mengirimkan perubahan ke repositori hulu dari proyek utama adalah untuk memastikan bahwa semua perubahan subtree kami tidak langsung ke repositori utama, tetapi berasal dari repositori upstream subtree seolah-olah kami menerima mereka menggunakan perintah git-subtree-pull . Selanjutnya, kami akan menjelaskan arti dari tindakan kami, dan sekarang, untuk menghindari masalah selanjutnya, kami akan mengembalikan komit terakhir ( abaa2c5edd49dd0cf395c99877b4711d0170af37 ) ke salinan lokal dari repositori platform :
bash-4.4$ bash-4.4$ git reset --hard HEAD^ HEAD is now at ea52eab Pull changes from master of upstream build-system.git repository. bash-4.4$
untuk kemudian "menghapus" komit yang sama kembali, tetapi dari repositori hulu remote / build-system.git asli . Tapi pertama-tama, pastikan bahwa kami menghapus komit terakhir abaa2c5edd49dd0cf395c99877b4711d0170af37 :
bash-4.4$ bash-4.4$ git log -3 --graph * commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (HEAD -> master, origin/master) |\ Merge: 442c9e9 e5c5446 | | Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 bash-4.4$
, ea52eabd5910159efabd80adcf522f22bf6a2af2 , remote/build-system.git . , , git-subtree-pull :
bash-4.4$ bash-4.4$ git subtree pull --prefix=build-system ../../remote/build-system.git/ master From ../../remote/build-system * branch master -> FETCH_HEAD hint: Waiting for your editor to close the file...
, :
Merge commit '0673142942ccf53514a276e855a98514952bb713'
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
:
Pull changes from master of origin remote/build-system repository.
Merge commit '0673142942ccf53514a276e855a98514952bb713'
, , :
Merge made by the 'recursive' strategy. build-system/README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
, , remote/build-system.git - . , build-system platform , remote/build-system.git :
bash-4.4$ bash-4.4$ git log --graph * commit 04a13bac91d1c445994ffc19db8b479d5e644e17 (HEAD -> master) |\ Merge: ea52eab 0673142 | | Author: user <___@_______> | | Date: Thu Nov 1 21:59:45 2018 +0300 | | | | Pull changes from master of origin remote/build-system repository. | | | | Merge commit '0673142942ccf53514a276e855a98514952bb713' | | | * commit 0673142942ccf53514a276e855a98514952bb713 | | Author: user <___@_______> | | Date: Thu Nov 1 21:48:40 2018 +0300 | | | | build-system is updated to version 1.0.2 from platform side | | * | commit ea52eabd5910159efabd80adcf522f22bf6a2af2 (origin/master) |\ \ Merge: 442c9e9 e5c5446 | |/ Author: user <___@_______> | | Date: Thu Nov 1 20:48:05 2018 +0300 | | | | Pull changes from master of upstream build-system.git repository. | | | | Merge commit 'e5c5446967599065dc02a269d8fcfc2c1d3c4f65' | | | * commit e5c5446967599065dc02a269d8fcfc2c1d3c4f65 | | Author: user <___@_______> | | Date: Thu Nov 1 20:26:52 2018 +0300 | | | | update build-system version to 1.0.1 | | * | commit 442c9e94c9890032fb2f3123661345d465e2849f | | Author: user <___@_______> | | Date: Thu Nov 1 20:41:40 2018 +0300 | | | | update platform version to 1.0.1 | | * | commit 47905bcb80be6f7cb3030513986fad4df548f812 |\ \ Merge: 7fad4be 783c6d5 | |/ Author: user <___@_______> | | Date: Thu Nov 1 20:20:20 2018 +0300 | | | | Add 'build-system/' from commit '783c6d5af1100e9665f930c818c861ff011bed19' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7fad4becbd13258216fb95cbe9d987dd33f0be6d | | git-subtree-split: 783c6d5af1100e9665f930c818c861ff011bed19 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: master | | | * commit 783c6d5af1100e9665f930c818c861ff011bed19 | Author: user <___@_______> | Date: Thu Nov 1 20:16:33 2018 +0300 | | init build-system master 1.0.0 | * commit 7fad4becbd13258216fb95cbe9d987dd33f0be6d Author: user <___@_______> Date: Thu Nov 1 20:16:33 2018 +0300 init platform master 1.0.0 bash-4.4$
, , upstream- remote/platform.git .
bash-4.4$ bash-4.4$ git status On branch master Your branch is ahead of 'origin/master' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean bash-4.4$ bash-4.4$ git push Enumerating objects: 9, done. Counting objects: 100% (8/8), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 600 bytes | 600.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git ea52eab..04a13ba master -> master bash-4.4$
, git-subtree-pull , . , git-push(1) , , , .
, upstream- remote/platform.git 04a13bac91d1c445994ffc19db8b479d5e644e17 , remote/build-system.git , , git-subtree-pull , upstream- remote/platform.git , upstream- remote/platform.git (owner/platform).
git-format-patch
, , git-subtre ,
:
git log -- . ":(exclude)build-system" git log -- build-system
, , .
git-format-patch .
, , patch- ea52eabd5910159efabd80adcf522f22bf6a2af2 , git-format-patch :
bash-4.4$ bash-4.4$ git format-patch ea52eabd5910159efabd80adcf522f22bf6a2af2 --stdout From 0673142942ccf53514a276e855a98514952bb713 Mon Sep 17 00:00:00 2001 From: user <___@_______> Date: Thu, 1 Nov 2018 21:48:40 +0300 Subject: [PATCH] build-system is updated to version 1.0.2 from platform side --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 629b3f4..4fbbbaf 100644 --- a/README +++ b/README @@ -1,3 +1,3 @@ -[master] build-system 1.0.1 +[master] build-system 1.0.2 -- 2.19.1 bash-4.4$
, build-system/README build-system/, :
--- a/README +++ b/README
,
git-diff :
bash-4.4$ bash-4.4$ git diff ea52eabd5910159efabd80adcf522f22bf6a2af2 04a13bac91d1c445994ffc19db8b479d5e644e17 diff --git a/build-system/README b/build-system/README index 629b3f4..4fbbbaf 100644 --- a/build-system/README +++ b/build-system/README @@ -1,3 +1,3 @@ -[master] build-system 1.0.1 +[master] build-system 1.0.2 bash-4.4$
patch-:
--- a/build-system/README +++ b/build-system/README
git-diff(1) , , , platform .
Politisi
CM- , . , , :
, .
, , upstream- remote/build-system.git :
bash-4.4$ bash-4.4$ cd owner/build-system/ bash-4.4$ cat README [master] build-system 1.0.2 bash-4.4$
, upstream- remote/build-system.git , , , minor 1.0.2 . build-system-1.1.x , , : 1.1.0 , 1.1.1 , 1.1.2 , .
:
bash-4.4$ bash-4.4$ git checkout -b build-system-1.1.x Switched to a new branch 'build-system-1.1.x' bash-4.4$ git branch * build-system-1.1.x master bash-4.4$
, README 1.1.0 :
bash-4.4$ bash-4.4$ vim README bash-4.4$ cat README [master] build-system 1.1.0 bash-4.4$ bash-4.4$ git commit -a -m "Move on to developing 1.1.x functionality" [build-system-1.1.x f6d79c1] Move on to developing 1.1.x functionality 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
upstream- remote/build-system.git :
bash-4.4$ bash-4.4$ git push --set-upstream origin build-system-1.1.x Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 280 bytes | 280.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git * [new branch] build-system-1.1.x -> build-system-1.1.x Branch 'build-system-1.1.x' set up to track remote branch 'build-system-1.1.x' from 'origin'. bash-4.4$
, , , 1.1.1 :
bash-4.4$ bash-4.4$ vim README bash-4.4$ cat README [master] build-system 1.1.1 bash-4.4$ bash-4.4$ git commit -a -m "Update build-system version to 1.1.1" [build-system-1.1.x f9544a4] Update build-system version to 1.1.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$ bash-4.4$ git push Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 276 bytes | 276.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git f6d79c1..f9544a4 build-system-1.1.x -> build-system-1.1.x bash-4.4$
:
bash-4.4$ bash-4.4$ git tag -a 1.1.1 -m "Created tag for release (version 1.1.1)" bash-4.4$ git push origin 1.1.1 Enumerating objects: 1, done. Counting objects: 100% (1/1), done. Writing objects: 100% (1/1), 170 bytes | 170.00 KiB/s, done. Total 1 (delta 0), reused 0 (delta 0) To ../../remote/build-system.git * [new tag] 1.1.1 -> 1.1.1 bash-4.4$
upstream- remote/build-system.git :
bash-4.4$ bash-4.4$ cd remote/build-system.git/ bash-4.4$ tree refs refs βββ heads β βββ build-system-1.1.x β βββ master βββ tags βββ 1.1.1 2 directories, 3 files bash-4.4$
, platform build-system . , , , , platform-1.0.2 :
bash-4.4$ bash-4.4$ cd user/platform/ bash-4.4$ git branch * master bash-4.4$ git pull Already up to date. bash-4.4$ bash-4.4$ git checkout -b platform-1.0.2 Switched to a new branch 'platform-1.0.2' bash-4.4$ vim README bash-4.4$ cat README [master] platform 1.0.2 bash-4.4$ git commit -a -m "reated platform-1.0.2 branch for the transition to the system 1.1.1" [platform-1.0.2 00a1250] reated platform-1.0.2 branch for the transition to the system 1.1.1 1 file changed, 1 insertion(+), 1 deletion(-) bash-4.4$
, , - remote/build-system.git , 1.1.1 :
bash-4.4$ bash-4.4$ git rm -rf build-system/ rm 'build-system/README' bash-4.4$ git commit -a -m "Removed subtre based on build-system/master" [platform-1.0.2 7db0f54] Removed subtre based on build-system/master 1 file changed, 3 deletions(-) delete mode 100644 build-system/README bash-4.4$ bash-4.4$ bash-4.4$ git push --set-upstream origin platform-1.0.2 Enumerating objects: 7, done. Counting objects: 100% (7/7), done. Delta compression using up to 4 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (5/5), 550 bytes | 550.00 KiB/s, done. Total 5 (delta 0), reused 0 (delta 0) To ../../remote/platform.git/ * [new branch] platform-1.0.2 -> platform-1.0.2 Branch 'platform-1.0.2' set up to track remote branch 'platform-1.0.2' from 'origin'. bash-4.4$ bash-4.4$ bash-4.4$ git subtree add --prefix=build-system ../../remote/build-system.git/ 1.1.1 git fetch ../../remote/build-system.git/ 1.1.1 remote: Enumerating objects: 9, done. remote: Counting objects: 100% (9/9), done. remote: Compressing objects: 100% (3/3), done. remote: Total 7 (delta 0), reused 0 (delta 0) Unpacking objects: 100% (7/7), done. From ../../remote/build-system * tag 1.1.1 -> FETCH_HEAD Added dir 'build-system' bash-4.4$
build-system upstream- remote/platform.git :
bash-4.4$ bash-4.4$ git push Enumerating objects: 12, done. Counting objects: 100% (12/12), done. Delta compression using up to 4 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (8/8), 889 bytes | 889.00 KiB/s, done. Total 8 (delta 0), reused 0 (delta 0) To ../../remote/platform.git/ 7db0f54..6f1a50e platform-1.0.2 -> platform-1.0.2 bash-4.4$
:
bash-4.4$ bash-4.4$ git log -3 --graph * commit 6f1a50e249e01f69c54f343b65747d28abc6456d (HEAD -> platform-1.0.2, origin/platform-1.0.2) |\ Merge: 7db0f54 f9544a4 | | Author: user <___@_______> | | Date: Fri Nov 2 18:24:54 2018 +0300 | | | | Add 'build-system/' from commit 'f045926542e9f685034545a45317093383fddf99' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7db0f5452e67086dc4e381a0ccb14f25d48ecf0b | | git-subtree-split: f045926542e9f685034545a45317093383fddf99 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: 1.1.1 | | | * commit f9544a4cc2650a83b96f400fdfc95ba64a38ec6e | | Author: user <___@_______> | | Date: Fri Nov 2 17:59:43 2018 +0300 | | | | Update build-system version to 1.1.1 | | | * commit f6d79c12ada29438454739fe6f6db9592d413be2 | | Author: user <___@_______> | | Date: Fri Nov 2 17:54:35 2018 +0300 | | | | Move on to developing 1.1.x functionality bash-4.4$
, CM- , platform , platform-1.0.2 build-system . , , build-system , .
, upstream- build-system platform , pre-receive
remote/build-system.git/hooks/pre-receive
, , :
. , , , , , , . , , :
git subtree push --prefix=<subdir> <remote> <ref>
<ref> , <subdir> , , (refs/tags/1.1.1), (1.1.1) upstream- ( : refs/heads/1.1.1).
, git-subtree(1) . .
, pre-receive , user/platform/build-system/README:
bash-4.4$ bash-4.4$ cd user/platform/ bash-4.4$ vim build-system/README bash-4.4$ cat build-system/README [master] build-system 1.1.1 Try to change. bash-4.4$ bash-4.4$ git commit -a -m "Try to change the tag of build-system" [platform-1.0.2 34e7970] Try to change the tag of build-system 1 file changed, 2 insertions(+) bash-4.4$
upstream- remote/build-system.git .
...upstream-
git subtree push --prefix=<subdir> <remote> <ref>
, , , :
bash-4.4$ git subtree -d --list Looking for externals... Commit: 6f1a50e249e01f69c54f343b65747d28abc6456d build-system ../../remote/build-system.git/ tag 1.1.1 f045926542e9f685034545a45317093383fddf99 bash-4.4$
, , upstream- remote/build-system.git :
bash-4.4$ bash-4.4$ git subtree push --prefix=build-system ../../remote/build-system.git/ 1.1.1 git push using: ../../remote/build-system.git/ 1.1.1 Enumerating objects: 5, done. Counting objects: 100% (5/5), done. Writing objects: 100% (3/3), 293 bytes | 293.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0) remote: remote: ERROR: Trying to change TAG named as 'refs/tags/1.1.1'. remote: To ../../remote/build-system.git/ ! [remote rejected] c3a7333aaa818a7d7a0d501d4b69db1c6a01d40f -> 1.1.1 (pre-receive hook declined) error: failed to push some refs to '../../remote/build-system.git/' bash-4.4$
, , pre-receive , . :
remote: remote: ERROR: Trying to change TAG named as 'refs/tags/1.1.1'. remote:
, , , , :
bash-4.4$ bash-4.4$ git reset --hard HEAD^ HEAD is now at 6f1a50e Add 'build-system/' from commit 'f045926542e9f685034545a45317093383fddf99' bash-4.4$
, , platform-1.0.2 :
bash-4.4$ bash-4.4$ git log -3 --graph * commit 6f1a50e249e01f69c54f343b65747d28abc6456d (HEAD -> platform-1.0.2, origin/platform-1.0.2) |\ Merge: 7db0f54 f9544a4 | | Author: user <___@_______> | | Date: Fri Nov 2 18:24:54 2018 +0300 | | | | Add 'build-system/' from commit 'f045926542e9f685034545a45317093383fddf99' | | | | git-subtree-dir: build-system | | git-subtree-mainline: 7db0f5452e67086dc4e381a0ccb14f25d48ecf0b | | git-subtree-split: f045926542e9f685034545a45317093383fddf99 | | git-subtree-repo: ../../remote/build-system.git/ | | git-subtree-ref: 1.1.1 | | | * commit f9544a4cc2650a83b96f400fdfc95ba64a38ec6e | | Author: user <___@_______> | | Date: Fri Nov 2 17:59:43 2018 +0300 | | | | Update build-system version to 1.1.1 | | | * commit f6d79c12ada29438454739fe6f6db9592d413be2 | | Author: user <___@_______> | | Date: Fri Nov 2 17:54:35 2018 +0300 | | | | Move on to developing 1.1.x functionality bash-4.4$
git-subrepo , , squashed-, git-subtree(1) , .
, . git-subrepo . , git-subtree , , Git , , , Git .
: