2012-11-29 24 views
5

विलय के बाद बस नई फ़ाइलें नहीं हैं मान लीजिए कि मेरे पास 2 शाखाएं, master और other हैं।गिट मास्टर शाखा में

मैं other शाखा में जाता हूं, 2 फाइलें जोड़ता हूं, प्रतिबद्ध करता हूं और पुश करता हूं।

अब मैं master शाखा में जाता हूं, फ़ाइलों को एक अलग निर्देशिका में जोड़ता हूं, और उन्हें प्रतिबद्ध करता हूं। फिर मैं other मर्ज करता हूं।

समस्या यह है कि मैंने other में जो फ़ाइलें शामिल की हैं, वे दिखाई नहीं दे रहे हैं। गिट का कहना है कि यह अद्यतित है, लेकिन इसकी नहीं! फाइलें गायब हैं

other में फ़ाइलों को जोड़ने के लिए मैं master को कैसे मजबूर कर सकता हूं या किसी भी तरह मैन्युअल रूप से उन्हें जोड़ सकता हूं? कार्ल के लिए

संपादित करें:

मैं हालांकि परिवर्तन है कि दिखाई नहीं दे रहे कई हफ्तों के पुराने हैं मेरी जानकारी के लिए निम्न किया था,। मुझे अभी एहसास हुआ कि वे आज वहां नहीं थे।

$ git branch 
*other 
master 
$ git add . 
$ git commit -m 'cool new features' 
$ git push origin other 
$ git checkout master 
$ git merge other 
$ git add . 
$ git commit -m 'merged cool new features from other' 
$ git push origin master 

मैं गीथूब पर जाता हूं, और फाइलें वहां नहीं हैं। अन्य फाइलें प्रतिबद्ध थीं और दिखायी गयी थीं, लेकिन दो फ़ोल्डर्स में मेल खाने वाली सामग्री नहीं है। फाइलें other में मौजूद हैं लेकिन master में नहीं हैं। स्पष्टीकरण के लिए, फाइलें नई नहीं थीं। लेकिन मैंने सोचा कि विलय कम से कम master पर फाइलों की प्रतिलिपि बनायेगा यदि वे मौजूद नहीं हैं!

+0

हाय, क्या आप वाकई अपनी फाइलें कर रहे हैं? मर्ज के दौरान गिट उन्हें छिपाने का कोई कारण नहीं है। क्या आप अपने द्वारा किए गए सभी आदेश पोस्ट कर सकते हैं? (इससे समस्या का पता लगाने में मदद मिलेगी) –

+0

गिट एड।, गिट प्रतिबद्ध-एम 'कुछ', गिट पुश, गिट चेकआउट, गिट मर्ज। शायद अब तक हर आदेश में और कई बार – AJcodez

+0

और यदि आप 'अन्य' शाखा में 'गिट स्थिति' करते हैं तो क्या होगा? –

उत्तर

3
इस तरह

:

[email protected]:~/stackoverflow$ git init . 
Initialized empty Git repository in /home/karl/stackoverflow/.git/ 
[email protected]:~/stackoverflow$ touch common_file_a 
[email protected]:~/stackoverflow$ touch common_file_b 
[email protected]:~/stackoverflow$ git add . 
[email protected]:~/stackoverflow$ git commit -m "commit common files" 
[master (root-commit) 89a5cd0] commit common files 
0 files changed 
create mode 100644 common_file_a 
create mode 100644 common_file_b 
[email protected]:~/stackoverflow$ git checkout -b other 
Switched to a new branch 'other' 
[email protected]:~/stackoverflow$ mkdir other 
[email protected]:~/stackoverflow$ touch other/other_file_a 
[email protected]:~/stackoverflow$ touch other/other_file_b 
[email protected]:~/stackoverflow$ git add . 
[email protected]:~/stackoverflow$ git commit -m "commit other files" 
[other 9c7409c] commit other files 
0 files changed 
create mode 100644 other/other_file_a 
create mode 100644 other/other_file_b 
[email protected]:~/stackoverflow$ git checkout master 
Switched to branch 'master' 
[email protected]:~/stackoverflow$ touch master_file_a 
[email protected]:~/stackoverflow$ touch master_file_b 
[email protected]:~/stackoverflow$ git add . 
[email protected]:~/stackoverflow$ git commit -m "commit master files" 
[master 3558768] commit master files 
0 files changed 
create mode 100644 master_file_a 
create mode 100644 master_file_b 
[email protected]:~/stackoverflow$ ls 
common_file_a common_file_b master_file_a master_file_b 
[email protected]:~/stackoverflow$ git merge other 
Merge made by the 'recursive' strategy. 
0 files changed 
create mode 100644 other/other_file_a 
create mode 100644 other/other_file_b 
[email protected]:~/stackoverflow$ ls 
common_file_a common_file_b master_file_a master_file_b other 
[email protected]:~/stackoverflow$ ls other 
other_file_a other_file_b 

आप अलग परिणाम हो रही है, तो आप या तो एक कदम लापता, एक अतिरिक्त कदम कहीं डाल, या तो आपको यह बताने नहीं कर रहे हैं त्रुटि के कुछ प्रकार हो रही है एक विलय संघर्ष की तरह, हम के बारे में। हमारे पास यह जानने का कोई तरीका नहीं है कि क्यों कुछ मूलभूत आपके लिए काम नहीं कर रहा है जब तक कि आप सटीक आदेश और आउटपुट जो आप प्राप्त कर रहे हैं, पोस्ट करते हैं।

2

यह थोड़ा देर हो चुकी है, लेकिन अन्य उपयोगकर्ताओं के लिए जो इस प्रश्न को ढूंढते हैं, मैं ऐसी स्थिति का वर्णन करूंगा जहां एजेकोडज़ द्वारा देखी गई समस्या होगी। यदि आप git checkout master; git merge other करते हैं, जिसके दौरान आप master (और संभवतः उस तथ्य के बारे में भूल जाते हैं) में कुछ नई फ़ाइलों को हटाते हैं और बाद में git checkout master; git merge other फिर से करते हैं, तो "नई" फ़ाइलें master में फिर से दिखाई नहीं देगी, क्योंकि वे हैं नया नहीं। विलय केवल मर्ज-बेस के सापेक्ष परिवर्तनों की परवाह करता है, जो कि दोनों शाखाओं के माध्यम से सबसे छोटी प्रतिबद्धता है। आपके दूसरे विलय के दौरान, मर्ज-बेस आपके पहले विलय के दौरान समान नहीं है, वर्णित परिदृश्य में दूसरे विलय के दौरान विलय-आधार वह प्रतिबद्धता है जो पहले विलय के दौरान other की नोक थी। यदि other तब से नई फ़ाइलों को नहीं बदला है, तो master में हटाना सबसे वर्तमान परिवर्तन है और इसलिए दूसरी फाइलों को हटाने के बाद नई फाइलों को हटाना राज्य होगा।

कि असुविधाजनक लगता है, तो आप एक अस्थायी शाखा (यह merge_branch कॉल) बनाने --squash का उपयोग कर इसे में other विलय, करने, master में विलय और अस्थायी शाखा को हटा कर उसके चारों ओर हो सकता है। यह शायद आदर्श समाधान नहीं है (उदाहरण के लिए पहले से ही हल किए गए विलय विवादों को फिर से हल किया जाना पड़ सकता है), लेकिन फिर मूल स्थिति शायद पहले ही गलती का परिणाम है।यहाँ मैं कोड में क्या मतलब है:

git log other # find the commit where 'other' originally branched off 
git checkout -b merge_branch COMMIT_ID # go there & create branch 
# without '--squash', the following merge would simply be a fast-forward 
# merge and wouldn't solve our problem, because 'merge_branch' would then 
# point to the same commit as 'other' and so the later merge into 
# 'master' would produce the same unsatisfactory result. 
git merge --squash other # does not create a new commit by itself 
git commit # better add an explanation for what you did and why 
# 'merge_branch' now contains everything you did in 'other' since it 
# branched off from 'master', but squashed into a single new commit 
git checkout master 
git merge merge_branch 
git branch --delete merge_branch 
1

मैं मास्टर शाखा में एक ही नाम के साथ खाली फ़ाइल बनाने के द्वारा इस समस्या का समाधान:

मान लीजिए, शाखा other एक नई फ़ाइल newfile.txt कि नहीं था शामिल master पर किसी भी तरह विलय किया गया।

git checkout master 
touch newfile.txt 
git add newfile.txt 
git commit -m "create newfile.txt" 
git merge other 

यह गंदा है, लेकिन काम करता है।

संबंधित मुद्दे