Git Merge 2: Çakışmaları (Conflict) Çözmek | Git Dersleri

Git Merge 2: Çakışmaları (Conflict) Çözmek | Git Dersleri

Merhabalar, geçenki dersimizde git ile iki dalı birleştirmeyi, git merge komutunu görmüştük. Bu dersimizde ise merge işleminden kaynaklanan conflict yani çakışmaları görüp bu çakışmanın nasıl çözüleceğini göreceğiz.

Bir versiyon kontrol sistemi kullandığınızda yaşayacağınız en büyük problem çakışmalardır. Bu çakışmalar yaptığınız geliştirmeye bağlı olarak bazen basitçe çözebilir bazen de saatlerce zamanınızı alabilir. Hatta ekip içinde tatsızlıklara bile sebep olabilir.

Çakıma aslında çok basit bir şekilde karşımıza çıkabilir. İki kişi aynı dosyayı ve aynı satırı değiştirirse ve git otomatik olarak merge edemezse bu durumda conflict yani çakışma olacaktır. Bu durumda çakışma yaşayan kişi gerekirse ekipteki diğer kişi ile beraber oturup çakışmayı çözdükten sonra merge işlemine devam etmelidir.

Depomuzun Son Hali

Geçen dersimizden hatırladığımız gibi chapter2 ve chapter3 branch’lerini master‘a birleştirmiştik. story.txt dosyamızda üç bölüme ait paragraflar yer alıyor.

Conflict sorununa geçmeden önce story.txt dosyamızı biraz daha takip edilebilir bir hale getirelim. story.txt dosyasında her bölümün başına hangi ‘Chapter’ a ait olduğunu ekleyelim. Dosyamızın son hali aşağıdaki gibi olacaktır.

Chapter 1
=======

Nearly twenty years after the Black Mesa Incident the G-Man wakes Gordon Freeman and inserts him (seemingly, without any goals) into a train arriving in City 17, a city under control of the Combine Empire located somewhere in Eastern Europe.

After leaving the train, Gordon and other passengers are welcomed by a broadcast by Dr. Wallace Breen, former administrator of Black Mesa, who is now Earth’s administrator. Continuing on his way, Gordon meets armed Civil Protection officers policing the train station and its surroundings. One of them separates him from the rest of the arriving citizens and directs him into a small interrogation room before revealing himself to be former Black Mesa security guard Barney Calhoun, operating
undercover for the Resistance.

Barney contacts Dr. Isaac Kleiner, Gordon’s mentor from his MIT days and former Black Mesa employee. After a bit of discussion they decide to send Gordon over to Kleiner’s Lab. Along the way, Gordon finds himself in the middle of a Civil Protection raid on a tenement house; after being captured, Gordon is rescued by a young woman named Alyx Vance.

Chapter 2
==========

Alyx, daughter of Eli Vance, a former Black Mesa employee now leading the Resistance against the Combine, takes Gordon to Dr. Kleiner’s lab, where he is given an H.E.V. Suit and instructed to be teleported to Black Mesa East with Alyx where he will be able to work alongside other scientists.

After teleporting Alyx, Gordon is next, but the interruption from Kleiner’s pet headcrab, Lamarr, causes a malfunction in the teleporter leading Gordon to Dr. Breen’s office, who recognizes him as a threat and puts the Combine forces on alert.

Following the failed teleport sequence, Gordon’s only option is to go on foot through the old Canals, with Civil Protection officers in hot pursuit. Before starting his journey, Gordon is given a Crowbar by Barney.

Chapter 3
===========

With the Crowbar Gordon is able to disarm two Civil Protection officers who had cornered a couple of Citizens, obtaining in this way his first firearm, the USP Match. Being armed allows Gordon to defeat all Civil Protection Units dispatched to the area before reaching Station 12, one of the many stations set up by the Underground Railroad, a network helping refugees escape City 17.

Most of these Stations and outposts are already under attack by the time Gordon arrives; generally filled with Manhacks or being bombarded with Headcrab Shells.

Eventually, Gordon reaches Station 6 (now under attack by Headcrabs); where he receives the Airboat, a makeshift vessel with an aircraft-type propeller, to help him traverse the toxic system of canals and get to Black Mesa East quick and safely.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

Chapter 1

=======

Nearly twenty years after the Black Mesa Incident the GMan wakes Gordon Freeman and inserts him (seemingly, without any goals) into a train arriving in City 17, a city under control of the Combine Empire located somewhere in Eastern Europe.

After leaving the train, Gordon and other passengers are welcomed by a broadcast by Dr. Wallace Breen, former administrator of Black Mesa, who is now Earth‘s administrator. Continuing on his way, Gordon meets armed Civil Protection officers policing the train station and its surroundings. One of them separates him from the rest of the arriving citizens and directs him into a small interrogation room before revealing himself to be former Black Mesa security guard Barney Calhoun, operating

undercover for the Resistance.

Barney contacts Dr. Isaac Kleiner, Gordon’s mentor from his MIT days and former Black Mesa employee. After a bit of discussion they decide to send Gordon over to Kleiner‘s Lab. Along the way, Gordon finds himself in the middle of a Civil Protection raid on a tenement house; after being captured, Gordon is rescued by a young woman named Alyx Vance.

Chapter 2

==========

Alyx, daughter of Eli Vance, a former Black Mesa employee now leading the Resistance against the Combine, takes Gordon to Dr. Kleiner’s lab, where he is given an H.E.V. Suit and instructed to be teleported to Black Mesa East with Alyx where he will be able to work alongside other scientists.

After teleporting Alyx, Gordon is next, but the interruption from Kleiner‘s pet headcrab, Lamarr, causes a malfunction in the teleporter leading Gordon to Dr. Breen’s office, who recognizes him as a threat and puts the Combine forces on alert.

Following the failed teleport sequence, Gordons only option is to go on foot through the old Canals, with Civil Protection officers in hot pursuit. Before starting his journey, Gordon is given a Crowbar by Barney.

Chapter 3

===========

With the Crowbar Gordon is able to disarm two Civil Protection officers who had cornered a couple of Citizens, obtaining in this way his first firearm, the USP Match. Being armed allows Gordon to defeat all Civil Protection Units dispatched to the area before reaching Station 12, one of the many stations set up by the Underground Railroad, a network helping refugees escape City 17.

Most of these Stations and outposts are already under attack by the time Gordon arrives; generally filled with Manhacks or being bombarded with Headcrab Shells.

Eventually, Gordon reaches Station 6 (now under attack by Headcrabs); where he receives the Airboat, a makeshift vessel with an aircrafttype propeller, to help him traverse the toxic system of canals and get to Black Mesa East quick and safely.

Şimdi bu dosyayı commit’leyelim.

Chapter 4 ve Chapter 5

Son commit’imizin ardından senaryomuza devam ediyoruz. Chapter 4 için ve Chapter 5 için bir branch oluşturup buraya commitlerimizi yapalım.

chapter4 branch’ini yaratıp aşağıdaki paragrafı commit’leyelim.

Aboard the airboat, Gordon fights off numerous Civil Protection units and a Hunter Chopper.

Aboard the airboat, Gordon fights off numerous Civil Protection units and a Hunter Chopper.

Şimdi sırada chapter5 ve aşağıdaki paragrafta. Branch’i master‘dan yaratmayı unutmayın!

Gordon Freeman finally reaches his destination, Black Mesa East, after a series of chases through the canals and waterways around City 17. Gordon meets Dr. Judith Mossman for the first time, and is reunited with Resistance Leader and former Black Mesa Scientist Eli Vance and Alyx. Gordon is also introduced to the Zero Point Energy Field Manipulator, also known as the ‘Gravity Gun’, a physics manipulator that quickly becomes indispensable, and after that, Gordon meets Dog, Alyx’s robotic “pet.”
Like A Red Letter Day, this chapter is full of insight and dialogue about the current state of the world, the people in it, and the aftermath of the Black Mesa Incident. While Gordon is playing with Dog in the scrapyard, Alyx spots Combine Scanners sweeping the area, shortly before an all out aerial raid on Black Mesa East. While attempting to rejoin the others, Gordon and Dog are separated from Alyx by a collapsed ceiling, and Gordon is forced to escape down a tunnel to Ravenholm, a place that
Alyx didn’t want to talk about earlier, showing obvious discomfort at the thought.

Gordon Freeman finally reaches his destination, Black Mesa East, after a series of chases through the canals and waterways around City 17. Gordon meets Dr. Judith Mossman for the first time, and is reunited with Resistance Leader and former Black Mesa Scientist Eli Vance and Alyx. Gordon is also introduced to the Zero Point Energy Field Manipulator, also known as the ‘Gravity Gun’, a physics manipulator that quickly becomes indispensable, and after that, Gordon meets Dog, Alyx‘s robotic “pet.”

Like A Red Letter Day, this chapter is full of insight and dialogue about the current state of the world, the people in it, and the aftermath of the Black Mesa Incident. While Gordon is playing with Dog in the scrapyard, Alyx spots Combine Scanners sweeping the area, shortly before an all out aerial raid on Black Mesa East. While attempting to rejoin the others, Gordon and Dog are separated from Alyx by a collapsed ceiling, and Gordon is forced to escape down a tunnel to Ravenholm, a place that

Alyx didn’t want to talk about earlier, showing obvious discomfort at the thought.

chapter4 vs chapter5

Şimdi elimizde iki branch var. Bu branch’lerin ikisini de master’a birleştirmemiz gerekiyor. Gelin öncelikle bu iki branch arasındaki farkları inceleyelim.

Hangisini önce getirelim? Aslında hiç farketmez. İlk master’a getiren çakışma yaşamayacak. Yani burda hızlı olan kazanıyor 🙂

master’a geri dönüp chapter4’ü merge edelim.

Conflict Zamanı

Şimdi chapter5’i merge edelim.

Aşağıdaki mesajı aldık.

Auto-merging story.txt
CONFLICT (content): Merge conflict in story.txt
Automatic merge failed; fix conflicts and then commit the result.

story.txt dosyasında bir conflict oluştuğunu açıklıyor. Şu an bu çakışmayı düzeltip tekrar bir commit yapmamız gerekecek. Düzeltme işlemine geçmeden önce story.txt dosyasının son satırlarına bakalım.

<<<<<<< HEAD Chapter 4 ============ Aboard the airboat, Gordon fights off numerous Civil Protection units and a Hunter Chopper. ======= Chapter 5 ============= Gordon Freeman finally reaches his destination, Black Mesa East, after a series of chases through the canals and waterways around City 17. Gordon meets Dr. Judith Mossman for the first time, and is reunited with Resistance Leader and former Black Mesa Scientist Eli Vance and Alyx. Gordon is also introduced to the Zero Point Energy Field Manipulator, also known as the 'Gravity Gun', a physics manipulator that quickly becomes indispensable, and after that, Gordon meets Dog, Alyx's robotic "pet." Like A Red Letter Day, this chapter is full of insight and dialogue about the current state of the world, the people in it, and the aftermath of the Black Mesa Incident. While Gordon is playing with Dog in the scrapyard, Alyx spots Combine Scanners sweeping the area, shortly before an all out aerial raid on Black Mesa East. While attempting to rejoin the others, Gordon and Dog are separated from Alyx by a collapsed ceiling, and Gordon is forced to escape down a tunnel to Ravenholm, a place that Alyx didn't want to talk about earlier, showing obvious discomfort at the thought. >>>>>>> chapter5

<<<<<<< HEAD

Chapter 4

============

Aboard the airboat, Gordon fights off numerous Civil Protection units and a Hunter Chopper.

=======

Chapter 5

=============

Gordon Freeman finally reaches his destination, Black Mesa East, after a series of chases through the canals and waterways around City 17. Gordon meets Dr. Judith Mossman for the first time, and is reunited with Resistance Leader and former Black Mesa Scientist Eli Vance and Alyx. Gordon is also introduced to the Zero Point Energy Field Manipulator, also known as the ‘Gravity Gun’, a physics manipulator that quickly becomes indispensable, and after that, Gordon meets Dog, Alyx‘s robotic “pet.”

Like A Red Letter Day, this chapter is full of insight and dialogue about the current state of the world, the people in it, and the aftermath of the Black Mesa Incident. While Gordon is playing with Dog in the scrapyard, Alyx spots Combine Scanners sweeping the area, shortly before an all out aerial raid on Black Mesa East. While attempting to rejoin the others, Gordon and Dog are separated from Alyx by a collapsed ceiling, and Gordon is forced to escape down a tunnel to Ravenholm, a place that

Alyx didn’t want to talk about earlier, showing obvious discomfort at the thought.

>>>>>>> chapter5

İçeriğe baktığımızda <<<<<<< HEAD yazan bir satır görüyorsunuz. Yine aynı şekilde bu paragrafın sonunda ======= bir satır daha var. (Kendi eklediğimiz satırla karıştırmayınız.) HEAD burda bulunduğumuz branch’in yani masterın son commitini ifade eder. Dosyanın devamında ise 5. bölümü ve sonunda da >>>>>>> chapter5 satırını görüyoruz. Git bize çakışma yaşadığımız değişiklikleri bu şekilde gösteriyor.

Bu aslında standard bir format. Unix sistemlerde diff komutunu kullandıysanız aynı formatta sonuç alırsınız. Hatta bir uygulama ile bu değişiklikleri daha güzel görebilirsiniz.

Örnek olarak kendi sistemime kurduğum Meld adlı uygulamada bu şekilde gözüküyor.

Melt diff ekranı

Yine eğer Eclipse, IntellijIdea gibi IDE kullanıyorsanız size yine daha güzel bir araç sağlayacaktır.

Çakışmayı (Conflict) Düzeltelim

Biz şimdi düzeltme işlemini yine vim kullanarak yapalım. Zaten burdaki çakışmayı çözmek oldukça basit. İstediğimiz her iki değişikliği de kabul etmek.

Şimdi bizden istenen commit’i gerçekleştirelim.

Böylece chapter5‘i de master’a birleştirmiş olduk. Bir git deposunda veya herhangi bir versiyon kontrol sisteminde sürekli aynı dosyayı değiştiriyorsanız çakışma sürekli karşınıza çıkacaktır. Yüzlerce satır kodda bu sorunu yaşadğınızı düşünün. İşin içinden çıkmak her zaman bu kadar kolay olmayacaktır. Bu sorunu yaşamak, ekibin yapısına, yazılılım geliştirirken kullandığınız programlama diline, uygulama çatılarına, yazılım prensiplerine uyup uymadığınıza vs. gibi bir çok etken bulunmaktadır. Örneğin bir Java uygulamasını ‘Tek Sorumluluk Prensibi (Singe Responsiblity Principe)’e uymayıp bütün kodu tek bir sınıfa yazarsanız, çakışma yaşamamanıza imkan yoktur.

Kullandığımız her araç ve o aracı nasıl kullandığımız da yazılım geliştiriken önemli konulardan biridir. Git ile ilgili ilerleyen derslerimizde bu konuları daha detaylı ele almayı düşünüyoruz.

Bu dersimizde conflict yani çakışma örneği görmüş olduk. Bir sonraki dersimizde artık uzak bir sunucu ile çalışmayı öğreneceğiz.

Konu hakkında görüş ve sorularınızı yorum kısmından veya Soru & Cevap sitemizden sorabilirsiniz.

Bir sonraki derste görüşmek üzere…

Git derslerinin tamamı için tıklayınız.

5

Yorum Yap
0 Yorum yapan