ఈ పేజీలో
git status
సంక్షిప్తంగా: git status అనేది ప్రస్తుత working directory, staging area (index), commit history (HEAD) స్థితిని పరిశీలించే read-only command. ఈ మూడు స్థితుల మధ్య వేగమైన three-way comparison చేసి, ఏ files untrackedగా, modifiedగా లేదా తదుపరి commit కోసం stagedగా ఉన్నాయో ఇది చూపిస్తుంది. మార్పులను డిస్క్లో రాయడానికి ముందు repository stateను గమనించడానికి ఇది ప్రధాన tool.
git status వాస్తవంగా ఏం చేస్తుంది?
Gitను నిజంగా అర్థం చేసుకోవాలంటే, ఇది కేవలం file diffsను ట్రాక్ చేసే tool అనే ఆలోచనను వదిలేయాలి. బదులుగా, Gitను మూడు వేర్వేరు content treesను నిర్వహించే managerగా ఊహించండి. ఈ trees మీ code lifecycleలోని వేర్వేరు దశలను సూచిస్తాయి:
- Working Directory (లేదా Working Tree): మీ operating system filesystemలోని అసలు sandbox. VS Code లేదా Vimలో fileను edit చేసినప్పుడు, మీరు నేరుగా Working Directoryనే మార్చుతున్నారు.
- Index (లేదా Staging Area):
.git/indexవద్ద నిల్వయ్యే binary cache file. ఇది pre-commit manifestలా పనిచేస్తుంది—తదుపరి commitలో ఉండే ఖచ్చితమైన file paths, permissions, files SHA-1 hashes కలిగిన ఒకే flat directory listing. - HEAD (చివరి Commit): ప్రస్తుత branch tipలోని commit objectకు pointer. HEAD మీ repositoryలోని అత్యంత తాజా checkpoint.
graph LR
subgraph "The Three Trees of Git"
A[Working Directory<br>Local Files] -->|git add| B[Index / Staging Area<br>.git/index]
B -->|git commit| C[HEAD<br>Last Commit]
end
style A fill:#f9f,stroke:#333,stroke-width:2px
style B fill:#bbf,stroke:#333,stroke-width:2px
style C fill:#bfb,stroke:#333,stroke-width:2px
మీరు git status నడిపినప్పుడు, Git మొత్తం commit historyని full scan చేయదు. బదులుగా, ఇది అత్యంత optimized three-way diff నడుపుతుంది:
- పోలిక A: Index vs. HEAD. Git staging area (
.git/index)లోని path-and-hash mappingsనుHEADచూపించే tree objectతో పోలుస్తుంది. Indexలోని file hash, HEADలోని hashతో వేరుగా ఉంటే, లేదా Indexలో ఉండి HEADలో లేకపోతే, అది “Changes to be committed” (staged)గా వర్గీకరించబడుతుంది. - పోలిక B: Working Directory vs. Index. Git hard driveలోని ప్రస్తుత filesను Indexలోని path-and-hash mappingsతో పోలుస్తుంది. working directoryలోని file state staging recordతో తేడాగా ఉంటే, అది “Changes not staged for commit” (modified)గా వర్గీకరించబడుతుంది.
- పోలిక C: Working Directory vs. Index (Untracked Check). working directoryలో కనిపించి, Indexలో సరిపోలే entry లేని file (మరియు
.gitignorerulesతో ignored కానిది) **“Untracked files”**గా వర్గీకరించబడుతుంది.
Stat Cache: git status ఎందుకు వెంటనే పూర్తవుతుంది?
వందల వేల files ఉన్న పెద్ద projectలో, Indexతో పోల్చడానికి working directoryలోని ప్రతి fileను hash చేయడం వల్ల git status చాలా నెమ్మదిగా మారుతుంది.
ఇది నివారించడానికి Git Stat Caching అనే పద్ధతిని ఉపయోగిస్తుంది. .git/index fileలో ప్రతి tracked fileకు సంబంధించిన metadata ఉంటుంది, అందులో ఇవి ఉన్నాయి:
- mtime: చివరిసారి మార్పు చేసిన timestamp.
- ctime: చివరిసారి metadata మారిన timestamp.
- dev / ino: filesystem device మరియు inode numbers.
- uid / gid: user మరియు group owners.
- file size: bytesలో file size.
మీరు git status నడిపినప్పుడు, Git working directory filesకు operating system filesystem statsను (చాలా వేగమైన lstat() system callతో) అడుగుతుంది. file size, inode లేదా modification time .git/indexలోని cached valuesతో సరిపోతే, file content మారలేదని Git నిర్ధారిస్తుంది. ఇది file content చదవడం, SHA-1 hashను మళ్లీ లెక్కించడం రెండింటినీ వదిలేస్తుంది. stat metadata వేరుగా ఉంటేనే Git fileను తెరిచి, hash చేసి, differences తనిఖీ చేస్తుంది.
.git/ లోపల ఏమి జరుగుతుంది? (చేతితో పరిశీలన)
కొత్త repository సృష్టించి, file lifecycleలో ప్రతి దశలో దాని internal file comparisons ఎలా మారుతున్నాయో గమనిస్తూ git status ప్రవర్తనను విడదీయండి.
దశ 1: Repositoryను initialize చేయడం
git init ఉపయోగించి clean repositoryని initialize చేయడం మొదలుపెడదాం.
$ mkdir git-status-demo && cd git-status-demo
$ git init
Initialized empty Git repository in /git-status-demo/.git/
.git directory స్థితిని తనిఖీ చేస్తే, ఇంకా index file లేదని, commits లేని default branchకు HEAD point అవుతోందని గమనిస్తాం.
$ cat .git/HEAD
ref: refs/heads/main
$ ls -l .git/index
ls: cannot access '.git/index': No such file or directory
ఇప్పుడు git status నడిపితే:
$ git status
On branch main
No commits yet
nothing to commit (create/copy files and use "git add" to track)
లోపల జరిగేది: Git .git/index కోసం చూసింది. అది కనిపించకపోవడంతో tracked files సంఖ్య సున్నా అని నిర్ణయించింది. ప్రస్తుత branch (main) తెలుసుకోవడానికి .git/HEAD చదివి, branch referenceను resolve చేసింది (ఇంకా commits లేనందున అది ఉండదు), ఆపై commits ఏవీ లేవని తేల్చింది.
దశ 2: Untracked ఫైల్ను చేర్చడం
README.md అనే ఫైల్ను సృష్టిద్దాం.
$ echo "# Git Status Demo" > README.md
ఇప్పుడు git status చూద్దాం:
$ git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
README.md
nothing added to commit but untracked files present (use "git add" to track)
లోపల జరిగేది:
- Git working directoryని scan చేసి
README.mdను కనుగొంటుంది. .git/indexచదవడానికి ప్రయత్నిస్తుంది. Index file ఇంకా లేదు.- File working directoryలో ఉండి indexలో లేకపోవడంతో, Git దాన్ని untrackedగా గుర్తిస్తుంది.
దశ 3: Fileను stage చేయడం
git add ఉపయోగించి ఫైల్ను stage చేద్దాం.
$ git add README.md
.git/ లోపల వెంటనే రెండు విషయాలు జరుగుతాయి:
- Git
README.mdcontentను compress చేసి, కొత్త blob objectను.git/objects/లో రాస్తుంది. - Git
.git/indexఫైల్ను సృష్టించి, file stats మరియు blob SHA-1 hashతోREADME.mdentryని రాస్తుంది.
Plumbing command git ls-files --stageతో index entryని నిర్ధారిద్దాం:
$ git ls-files --stage
100644 c5d3bc8d139371ff4cf9e97623b2255fb722b2d9 0 README.md
Blob .git/objects/లో ఉందో చూద్దాం:
$ git cat-file -t c5d3bc8d139371ff4cf9e97623b2255fb722b2d9
blob
$ git cat-file -p c5d3bc8d139371ff4cf9e97623b2255fb722b2d9
# Git Status Demo
ఇప్పుడు git status నడుపుదాం:
$ git status
On branch main
No commits yet
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: README.md
లోపల జరిగేది:
- Git
.git/HEAD->refs/heads/mainచదువుతుంది.refs/heads/mainreference ఇంకా లేదు (ఇంకా commits లేవు). - Git
.git/indexచదివి ఒక entryని కనుగొంటుంది:README.md, blobc5d3bc8d1393...ను చూపిస్తోంది. HEADఖాళీగా ఉండగా indexలోREADME.mdఉంది. అంటేHEADలో లేని file indexలో ఉంది. అందుకే file **staged for commit (new file)**గా చూపబడుతుంది.- Git
README.mdworking directory statను.git/indexలో cached statతో పోలుస్తుంది. అవి సరిపోవడంతో unstaged modifications ఏవీ లేవు.
దశ 4: Commit చేయడం
git commit ఉపయోగించి మార్పును commit చేద్దాం.
$ git commit -m "Initial commit"
[main (root-commit) 55a420b] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 README.md
ఇప్పుడు git status చూద్దాం:
$ git status
On branch main
nothing to commit, working tree clean
లోపల జరిగేది:
- Commit ఒక commit object (hash:
55a420b...) మరియు repository stateను చూపించే tree objectను సృష్టించింది. - Git
.git/refs/heads/mainను ఈ కొత్త commit object hashతో update చేసింది. git statusనడిచినప్పుడు, అదిHEAD->refs/heads/main-> commit55a420bను resolve చేస్తుంది.55a420bcommitలోని tree (README.mdను blobc5d3bc8d1393...తో జాబితా చేస్తుంది)ను staging index.git/indexతో (అదేREADME.md, అదే blobc5d3bc8d1393...తో) పోలుస్తుంది. Hashes ఒకటే కాబట్టి staged changes లేవు.- Index statsను filesystem statsతో పోలుస్తుంది. అవి సరిపోవడంతో modified changes లేవు.
దశ 5: Fileను మార్చడం
Working directoryలో README.mdను మార్చుదాం:
$ echo "# Git Status Demo" > README.md
$ echo "Added a new line of text." >> README.md
git status నడుపుదాం:
$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
లోపల జరిగేది:
- Git
README.mdపైlstat()పిలిచి metadata చదువుతుంది..git/indexentryతో పోలిస్తే modified time (mtime) మరియు file size మారాయి. - Git
README.mdను తెరిచి, మార్చిన contentకు SHA-1 hash లెక్కిస్తుంది (కొత్త hash:c7cb148f2e21f06939fe9ac90d42a302294f12dd). - లెక్కించిన hash
.git/indexలో నిల్వ ఉన్న hash (c5d3bc8d1393...)తో వేరుగా ఉండటంతో, ఫైల్ను modified but unstagedగా చూపిస్తుంది. - Git index entryని
HEADtree entryతో పోలుస్తుంది. రెండింటిలోనూc5d3bc8d1393...ఉండటంతో staged changes ఏవీ లేవు.
graph TD
subgraph "Three-Way Hash Comparison"
HEAD["HEAD Commit Tree<br>Hash: c2ba505..."]
Index["Staging Index<br>Hash: c2ba505..."]
Work["Working Directory<br>Hash: d78be55..."]
end
HEAD ===|Staged: Match| Index
Index---|Modified: Mismatch| Work
కమాండ్ ఎంపికలు మరియు అధునాతన వినియోగం
git status సులభమైనదే అయినా, scripting, debugging మరియు complex statesను చూడటానికి కొన్ని advanced options మరింత శక్తినిస్తాయి.
1. Short Format (--short లేదా -s)
చాలా modified filesతో పనిచేసేటప్పుడు default verbose output పెద్దదిగా అనిపించవచ్చు. Short format మార్పులను compact two-column layoutలో చూపిస్తుంది.
$ git status -s
M README.md
?? new_script.js
Columns Staging Area (column 1) మరియు Working Directory (column 2)ను సూచిస్తాయి:
M(col 1లో space, col 2లోM): working directoryలో file modified అయింది, కానీ modification staged కాదు.M(col 1లోM, col 2లో space): file modified అయి, మార్పు indexలో staged అయింది.MM(రెండు columnsలోనూ): file modified అయి, ఆ మార్పులు staged అయ్యాయి; తర్వాత working directoryలో fileను మళ్లీ modify చేశారు.A: file staging areaకు కొత్తగా చేర్చబడింది.??: file untrackedగా ఉంది.
2. Ignored filesను చేర్చడం (--ignored)
Defaultగా .gitignoreలోని patternsకు సరిపోయే files status నుంచి పూర్తిగా దాచబడతాయి. ఒక నిర్దిష్ట file ఎందుకు track కావడం లేదో troubleshooting చేస్తున్నప్పుడు --ignored flag ఉపయోగించండి.
$ echo "logs/" > .gitignore
$ mkdir logs && touch logs/debug.log
$ git status --ignored
On branch main
...
Ignored files:
(use "git add -f <file>..." to include in what will be committed)
logs/
3. --porcelainతో scripting
Repository dirtyగా ఉందో తెలుసుకోవాల్సిన shell script, git alias లేదా CI/CD script రాస్తుంటే, git status standard outputను ఎప్పుడూ parse చేయకండి (Git versions మధ్య అది మారవచ్చు). బదులుగా --porcelain ఉపయోగించండి.
$ git status --porcelain
M README.md
?? new_script.js
--porcelain flag output format future Git versionsలోనూ backwards-compatible మరియు stableగా ఉంటుందని హామీ ఇస్తుంది. ఇది predictable machine-readable formatలో output ఇస్తుంది; colors మరియు helper textను తొలగిస్తుంది.
Bash scriptలో repositoryకి uncommitted changes ఉన్నాయో త్వరగా చూడటానికి:
if [ -z "$(git status --porcelain)" ]; then
echo "Working directory is clean. Proceeding..."
else
echo "Error: You have uncommitted changes!" >&2
exit 1
fi
నిజ జీవిత పరిస్థితి: File permissions మరియు line endings
కొన్నిసార్లు git status file modified అని చూపిస్తుంది, కానీ git diff నడిపితే codeలో అసలు changes కనిపించవు. సాధారణంగా దీనికి line endings లేదా file mode changes అనే రెండు కారణాలు ఉంటాయి.
పరిస్థితి A: File permissions (chmod)
Git executable bits (100755 executablesకు, 100644 regular filesకు)ను track చేస్తుంది. మీరు లేదా script file permissionsను మార్చితే (ఉదా. chmod +x script.sh), Git file modified అని చూపిస్తుంది.
File permissions ముఖ్యం కాని projectలో (cross-platform Windows/macOS/Linux team వంటి సందర్భంలో) ఇది జరిగితే, permission changesను ignore చేయమని Gitకు configure చేయవచ్చు:
$ git config core.filemode false
పరిస్థితి B: Line ending inconsistencies (LF vs CRLF)
Windows systems చారిత్రకంగా lines ముగించడానికి Carriage Return + Line Feed (CRLF) ఉపయోగిస్తాయి; Linux మరియు macOS Line Feed (LF) ఉపయోగిస్తాయి. Text editor మీ line endingsను స్వయంచాలకంగా మార్చితే, binary hashes వేరుగా ఉండటం వల్ల Git మొత్తం file modifiedగా గుర్తిస్తుంది.
Line ending mismatchesను globally సరిచేయడానికి Git autocrlf setting configure చేయండి:
# On Windows
$ git config --global core.autocrlf true
# On macOS/Linux
$ git config --global core.autocrlf input
సాధారణ సమస్యలు మరియు తప్పులు
1. Subdirectoryలో git status నడపడం
Nested subdirectory నుంచి git status నడిపితే, Git defaultగా ఆ subdirectoryకి relative paths చూపిస్తుంది; దీనివల్ల paths గందరగోళంగా కనిపించవచ్చు. మీరు command ఎక్కడి నుంచి నడిపినా root directoryకి relative paths చూడాలంటే:
$ git status --relative=false
2. Staged file ఇంకా “Changes not staged for commit” కింద కనిపించడం
ప్రారంభకులకు ఇది తరచూ గందరగోళం కలిగించే విషయం. git add file.txtతో fileను stage చేసిన తర్వాత editor తెరిచి file.txtలో మరో line చేరిస్తే, git status fileను రెండుసార్లు చూపిస్తుంది:
Changes to be committed:
modified: file.txt
Changes not staged for commit:
modified: file.txt
మీరు git add నడిపిన క్షణంలోని file యొక్క exact snapshotను Git stage చేస్తుంది. ఆ తర్వాత చేసిన edits working directoryలోనే ఉంటాయి; వాటిని మళ్లీ stage చేయాలి.
3. .gitignoreలో ఉన్న file ఇంకా కనిపించడం
మీరు .gitignoreలో చేర్చే ముందు file Gitలో ఇప్పటికే trackedగా ఉంటే, అది మారినప్పుడు git statusలో కనిపిస్తూనే ఉంటుంది. .gitignore కేవలం untracked files track కాకుండా నిరోధిస్తుంది. మీ computer నుంచి fileను delete చేయకుండా tracking ఆపాలంటే, దాన్ని index నుంచి తొలగించాలి:
$ git rm --cached path/to/file.txt
కమాండ్ల త్వరిత సూచన
| Command | వివరణ |
|---|---|
git status | పూర్తి verbose formatలో status చూపిస్తుంది (default). |
git status -s / --short | సంక్షిప్త two-column formatలో status చూపిస్తుంది. |
git status -b / --branch | branch మరియు tracking branch వివరాలను చూపిస్తుంది (short formatకు context జత చేస్తుంది). |
git status --ignored | .gitignoreతో ignored అయిన ఫైళ్లను చూపిస్తుంది. |
git status --porcelain | machine parsing మరియు scriptingకు optimized output. |
git status -uall | untracked directories పేరు మాత్రమే కాకుండా, వాటిలోని individual ఫైళ్లను చూపిస్తుంది. |
FAQ (తరచుగా అడిగే ప్రశ్నలు)
git status “On branch main, nothing to commit, working tree clean” అని ఎందుకు చెబుతుంది?
Gitలోని మూడు trees పూర్తిగా ఒకే స్థితిలో ఉన్నాయని ఈ message చెబుతుంది. Working Directoryలోని అన్ని files SHA-1 hashes, Staging Index (.git/index)లోని hashesతో, అవి మళ్లీ HEAD commit treeలో నమోదైన hashesతో సరిపోతున్నాయి. చేయాల్సిన లేదా నమోదు చేయాల్సిన modifications ఏవీ లేవు.
File rename అయిందని git statusకు ఎలా తెలుస్తుంది?
Git renamesను నేరుగా track చేయదు. అది వాటిని detect చేస్తుంది. ఒక pathలో file delete అయి, మరో pathలో add అయినప్పుడు, git status indexను చదివి content hashesను పోలుస్తుంది. Deleted file మరియు added file content ఒకటే (లేదా చాలా similar) అయితే, Git similarity index లెక్కించి file renamedగా చూపిస్తుంది (ఉదా. renamed: old_file.txt -> new_file.txt).
git status నడపడం వల్ల నా files మారుతాయా?
లేదు. Working directory మరియు commit history పరంగా git status పూర్తిగా read-only. ఇది filesను inspect చేసి metadataను పోలుస్తుంది. అత్యధికంగా, తరువాతి commands పనితీరు మెరుగుపరచడానికి .git/indexలోని stat cacheని ప్రస్తుత filesystem timesతో update చేయవచ్చు; కానీ ఇది source codeను ఎప్పుడూ మార్చదు, changesను revert చేయదు.
Remote branch కంటే వెనుకబడి ఉన్నానా/ముందున్నానా తెలుసుకోవడానికి git statusను ఎలా ఉపయోగించాలి?
మీ local branch remote branchను (ఉదా. origin/main) track చేస్తుంటే, git status మీ local branch HEAD referenceను cached remote tracking reference (.git/refs/remotes/origin/main)తో పోలుస్తుంది. ఇది “Your branch is ahead of ‘origin/main’ by 2 commits” లేదా “Your branch is behind…” వంటి messages చూపిస్తుంది. ఇది మీ చివరి fetchపై ఆధారపడి ఉంటుందని గుర్తుంచుకోండి; git status remote serverను query చేయదు. కాబట్టి తాజా tracking information కోసం ముందుగా git fetch నడపండి.
మీ జ్ఞానాన్ని పరీక్షించుకోండి
క్విజ్ లోడ్ అవుతోంది…