मैं हमेशा इसके साथ भ्रमित हो जाता हूं, इसलिए यहां एक अनुस्मारक परीक्षण मामला है; मान लें कि हमारे पास bashपरीक्षण करने के लिए यह स्क्रिप्ट है git:
set -x
rm -rf test
mkdir test
cd test
git init
git config user.name test
git config user.email test@test.com
echo 1 > a.txt
echo 1 > b.txt
git add *
git commit -m "initial commit"
echo 2 >> b.txt
git add b.txt
git commit -m "second commit"
echo 3 >> b.txt
इस बिंदु पर, कैश में परिवर्तन का मंचन नहीं किया गया है, इस प्रकार git statusहै:
$ git status
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: b.txt
no changes added to commit (use "git add" and/or "git commit -a")
यदि इस बिंदु से, हम करते हैं git checkout, तो परिणाम यह है:
$ git checkout HEAD -- b.txt
$ git status
On branch master
nothing to commit, working directory clean
यदि इसके बजाय हम करते हैं git reset, तो परिणाम है:
$ git reset HEAD -- b.txt
Unstaged changes after reset:
M b.txt
$ git status
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: b.txt
no changes added to commit (use "git add" and/or "git commit -a")
तो, इस मामले में - यदि परिवर्तनों का मंचन नहीं किया जाता है, तो git resetकोई फर्क नहीं पड़ता है, जबकि git checkoutपरिवर्तनों को ओवरराइट करता है।
अब, मान लें कि ऊपर की स्क्रिप्ट से अंतिम परिवर्तन का मंचन / कैश किया गया है, यह कहना है कि हमने git add b.txtअंत में भी किया था ।
इस मामले में, git statusइस बिंदु पर है:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: b.txt
यदि इस बिंदु से, हम करते हैं git checkout, तो परिणाम यह है:
$ git checkout HEAD -- b.txt
$ git status
On branch master
nothing to commit, working directory clean
यदि इसके बजाय हम करते हैं git reset, तो परिणाम है:
$ git reset HEAD -- b.txt
Unstaged changes after reset:
M b.txt
$ git status
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: b.txt
no changes added to commit (use "git add" and/or "git commit -a")
तो, इस मामले में - यदि परिवर्तनों का मंचन किया जाता है, git resetतो मूल रूप से मंचित परिवर्तनों को अस्थिर परिवर्तनों में बदल देगा - जबकि git checkoutपरिवर्तनों को पूरी तरह से लिख देगा।