2012-12-09 9 views
5

मैं git commit -vप्रतिबद्ध होने से पहले फ़ाइल में परिवर्तन कैसे देखें?

[email protected]:~/agile$ git commit -v 
# On branch master 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: .htaccess 
# 
no changes added to commit (use "git add" and/or "git commit -a") 
[email protected]:~/agile$ 

की कोशिश की है लेकिन यह सिर्फ मुझे दिख रहा है कि .htaccess बदला है, लेकिन नहीं बदला है क्या। मुझे यह कैसे हासिल होगा?

अद्यतन: Aptana स्टूडियो में यह परिवर्तन इससे पहले कि आप कुछ भी करने को देखने के लिए संभव है। तो मेरे प्रश्न पर वापस, वास्तव में प्रतिबद्ध होने से पहले, मूल स्थिति में अंतर देखने का एक तरीका होना चाहिए। शायद इसके लिए एक अलग आदेश है।

उत्तर

10

सुनिश्चित करें कि आपने कुछ बदलाव किए हैं। अन्यथा, git commit -v आपको आपके द्वारा पोस्ट की गई एक ब्लॉक दिखाएगा, लेकिन कुछ भी नहीं करेगा। आप git add के साथ मैन्युअल रूप से परिवर्तन चरणबद्ध कर सकते हैं, या यदि फ़ाइलें पहले से ही संस्करणित हैं, तो आप चरण में git commit -a -v का उपयोग कर सकते हैं और परिवर्तन कर सकते हैं।

उदाहरण के लिए:

$ echo "more foo" >> foo.txt 
$ git commit -v 
# On branch master 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: foo.txt 
# 
no changes added to commit (use "git add" and/or "git commit -a") 

परिवर्तन मचान git commit -v साथ diff पता चलता है:

:: git add foo.txt 
:: GIT_EDITOR=cat git commit -v 

# Please enter the commit message for your changes. Lines starting 
# with '#' will be ignored, and an empty message aborts the commit. 
# On branch master 
# Changes to be committed: 
# (use "git reset HEAD <file>..." to unstage) 
# 
# modified: foo.txt 
# 
diff --git a/foo.txt b/foo.txt 
index 257cc56..a521556 100644 
--- a/foo.txt 
+++ b/foo.txt 
@@ -1 +1,2 @@ 
foo 
+more foo 
Aborting commit due to empty commit message. 

तुम सिर्फ करने के बिना diff को देखने के लिए, git diff उपयोग करने के लिए, unstaged परिवर्तन देखने के लिए git diff --cached चाहते हैं अपने काम करने वाले पेड़ में चरणबद्ध और अस्थिर परिवर्तन दोनों को देखने के लिए प्रतिबद्धता के लिए चरणबद्ध परिवर्तन, या git diff HEAD देखें।

अद्यतन: अपना संपादन दिया गया है, जो आप वास्तव में चाहते हैं git diff ऊपर डेरिवेटिव हैं। मुझे यकीन नहीं है कि कैसे Aptana स्टूडियो काम करता है। यह ठेठ कमांड लाइन गिट प्रवाह का पालन नहीं कर सकता है। कमांड लाइन पर, आप अपने परिवर्तनों को मंचित करेंगे, और फिर प्रतिबद्ध होंगे। और उपर्युक्त git diff कमांड वे हैं जो आप उन परिवर्तनों की जांच के लिए उपयोग करेंगे। मैं आमतौर पर उन्हें git unstaged, git staged, और git both के रूप में मेरे ~/.gitconfig को यह जोड़कर उपनाम:

[alias] 
    # show difference between working tree and the index 
    unstaged = diff 

    # show difference between the HEAD and the index 
    staged = diff --cached 

    # show staged and unstaged changes (what would be committed with "git commit -a") 
    both = diff HEAD 
+0

+1 हां। 'गिट diff। htaccess' जो मैं प्राप्त करना चाहता था। धन्यवाद :) – Houman

6

ट्रैक किए गए फ़ाइलों में सभी diff देखने के लिए लेकिन मंचन नहीं:

git diff 

या

git diff path/to/a/given/file 

केवल एक फ़ाइल के लिए diff देखने के लिए। आप भी अपनी परियोजना की दी गई सब-निर्देशिका में अंतर देख सकते हैं:

git diff path/to/a/dir/ 

आप पहले से ही git add के साथ परिवर्तन का मंचन किया है, तो आप देख सकते हैं कि पैच आप

git diff --staged 

साथ मंचन किया है आप --staged के साथ एक पथ भी निर्दिष्ट कर सकते हैं।

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