ఈ పేజీలో

git log

సంక్షిప్తంగా: ప్రాజెక్ట్ చరిత్రను ఆడిట్ చేయడానికి Gitలోని ప్రధాన సాధనం git log. ఇది కమిట్ల Directed Acyclic Graph (DAG)ను ప్రస్తుత checkout పాయింట్ (HEAD) నుంచి మొదలుపెట్టి, దాని parent hashes చదువుతూ, మొదటి root commit వరకు కాలంలో వెనక్కి recursiveగా సాగుతుంది. ఇది కేవలం టెక్స్ట్ జాబితా కాదు; శక్తివంతమైన search మరియు analysis సాధనం.

కింద ఉన్న hashes గురించి: ఈ పాఠంలోని commit మరియు tree IDs ఉదాహరణ కోసం మాత్రమే. Commit hash దాని tree, parents, author/committer identities, commit timestamp ఆధారంగా లెక్కించబడుతుంది — అందువల్ల మీరు ఇదే commands నడిపితే graph structure ఒకటే ఉండి IDs మాత్రం వేరుగా వస్తాయి. చూపించిన timestamps +0000 (UTC) offsetతో ఉన్న Unix epoch seconds.


git log నిజంగా ఏం చేస్తుంది?

git log మీ historyని ఎలా రూపొందిస్తుందో అర్థం చేసుకోవాలంటే Git commitsను ఎలా నిర్వహిస్తుందో చూడాలి. Git మీ commitsను flat list లేదా arrayలో నిల్వ చేయదు. బదులుగా, వాటిని **Directed Acyclic Graph (DAG)**గా నిర్మిస్తుంది.

ఈ graphలో:

  • Nodes: ఇవి మీ commit objects.
  • Edges: ఇవి child commit నుంచి దాని parent commit(s)కు వెళ్లే pointers. ఇవి directed (కాలంలో వెనక్కి చూపుతాయి), acyclic (history తనలోకే loop కాలేదు).
graph RL
    C3[Commit 3<br>HEAD / main] -->|parent| C2[Commit 2]
    C2 -->|parent| C1[Commit 1<br>Root Commit]

మీరు git log నడిపినప్పుడు Git మొత్తం diskను scan చేయదు. బదులుగా, ఇచ్చిన entry point నుంచి graph traversal చేస్తుంది — defaultగా HEAD చూపించే commit నుంచి (మీ ప్రస్తుత location, link git-checkout).

ట్రావర్సల్ అల్గోరిథం

  1. మీ active branchను తెలుసుకోవడానికి Git .git/HEAD fileను చదువుతుంది (ఉదా. ref: refs/heads/main).
  2. .git/refs/heads/mainను చదివి active branch referenceను దాని 40-character commit hashకు resolve చేస్తుంది (ఉదా. 8a4c10...).
  3. Object database (.git/objects/) నుంచి commit object 8a4c10...ను load చేసి metadataను తీసుకుంటుంది: Author, Committer, Timestamp, Message, మరియు parent hash.
  4. ఈ commit వివరాలను మీ consoleలో output చేస్తుంది.
  5. Parent hashను (ఉదా. 55a420...) traversal queueలో ఉంచుతుంది.
  6. Loop మళ్లీ మొదలవుతుంది: Git queue నుంచి తదుపరి commit hashను తీసుకుని, దాన్ని చదివి, చూపించి, దాని parentsను queueలో పెడుతుంది.
  7. ఏ commitకూ parent field లేకపోతే traversal ఆగుతుంది; అది repositoryలోని మొదటి commit (root commit) అని దీనర్థం.

Merge commitలో commit objectలో అనేక parent lines ఉంటాయి. Git అన్ని parent hashesను queueలో పెడుతుంది. Sorting settings (ఉదా. chronological, topological, లేదా date-ordered) ఆధారంగా, merged branchesలోని commitsను interleave చేసి ఒక unified timelineను తిరిగి నిర్మిస్తుంది.


.git/ లోపల ఏమి జరుగుతుంది (చేతితో పరిశీలన)

అనేక commits, branches ఉన్న repositoryని తయారు చేసి, git log outputను రూపొందించడానికి Git తన ఫైళ్లను ఎలా parse చేస్తుందో సరిగ్గా trace చేద్దాం.

దశ 1: Multi-commit repositoryని సిద్ధం చేయండి

ముందుగా repositoryని initialize చేసి, main branchపై రెండు చిన్న commits చేద్దాం.

$ mkdir git-log-demo && cd git-log-demo
$ git init
Initialized empty Git repository in /git-log-demo/.git/

$ echo "v1" > file.txt
$ git add file.txt
$ git commit -m "First commit"
[main (root-commit) 5be36ab] First commit

$ echo "v2" > file.txt
$ git add file.txt
$ git commit -m "Second commit"
[main ae39f81] Second commit

దశ 2: Branch మరియు merge commit సృష్టించండి

ఇప్పుడు feature అనే branchను (link git-branch) సృష్టించి, అందులో ఒక commit చేసి, తిరిగి mainకు మారి దాన్ని merge చేద్దాం.

$ git checkout -b feature
Switched to a new branch 'feature'

$ echo "feature-work" > feature.txt
$ git add feature.txt
$ git commit -m "Feature commit"
[feature c4f8101] Feature commit

$ git checkout main
Switched to branch 'main'

$ git merge feature -m "Merge feature branch"
Merge made by the 'ort' strategy.
 feature.txt | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 feature.txt

దశ 3: Refsను resolve చేసి commitsను catalog చేయండి

ప్రస్తుతం HEAD ఎక్కడికి చూపిస్తుందో చూద్దాం:

$ cat .git/HEAD
ref: refs/heads/main

ఇప్పుడు main ఏ commit hashను చూపిస్తుందో చూద్దాం:

$ cat .git/refs/heads/main
6df8d0354178de3d038fa61dfb63e8a157580b33

ఇది మన merge commit. Plumbing command git cat-file ఉపయోగించి ఈ commit objectను చూద్దాం:

$ git cat-file -p 6df8d0354178de3d038fa61dfb63e8a157580b33
tree e7c3909ea1dc725f187e1451f2ad490e5b0213ef
parent ae39f81ca99d45e5b619d854cf78d1f2a36b1d2e
parent c4f810129a8a72cf5a1db5b2f270a2936274b1e2
author Purna Pattela <purna@example.com> 1772960500 +0000
committer Purna Pattela <purna@example.com> 1772960500 +0000

Merge feature branch

ఇది merge commit కాబట్టి దీనికి రెండు parents ఉన్నాయని గమనించండి:

  • parent ae39f81... (mergeకు ముందు mainలోని చివరి commit).
  • parent c4f8101... (feature branchలోని commit).

git log నడిపితే Git merge commit (6df8d03)ను output చేసి, దాని parentsను చదువుతుంది. ఇది ae39f81 మరియు c4f8101 parentల మీద chronological orderలో traversal చేస్తుంది. ae39f81ను పరిశీలిద్దాం:

$ git cat-file -p ae39f81ca99d45e5b619d854cf78d1f2a36b1d2e
tree b4f93dc52c0dfa6c7f8a9a2a6dfba1d2a36b567d
parent 5be36abc0e9df7f2a7db2e9b0cf2a3d2427a1d1e
author Purna Pattela <purna@example.com> 1772960400 +0000
committer Purna Pattela <purna@example.com> 1772960400 +0000

Second commit

ఈ commit మొదటి parent 5be36ab... వైపు చూపిస్తుంది. 5be36abను చూద్దాం:

$ git cat-file -p 5be36abc0e9df7f2a7db2e9b0cf2a3d2427a1d1e
tree f3b3a3c9e6db5832a875a6c11d2b270a2936274b
author Purna Pattela <purna@example.com> 1772960300 +0000
committer Purna Pattela <purna@example.com> 1772960300 +0000

First commit

5be36ab...లో parent line లేదు. కాబట్టి ఇది మన treeకి root అని Gitకు తెలుస్తుంది, traversal ఆగుతుంది. ఫలితంగా వచ్చిన log output reverse chronological orderలో నాలుగు commitsను చూపిస్తుంది.


కమాండ్ ఎంపికలు మరియు అధునాతన వినియోగం

git log default output verboseగా, sequentialగా ఉంటుంది. Flagsతో historyని format, filter, trace చేయవచ్చు.

1. అధునాతన ఫార్మాటింగ్ ఎంపికలు

--oneline

ప్రతి commitను abbreviated commit hash, subject line ఉన్న ఒకే lineకు కుదిస్తుంది. Commit historiesను త్వరగా scan చేయడానికి ఇది అనుకూలం.

$ git log --oneline
6df8d03 Merge feature branch
c4f8101 Feature commit
ae39f81 Second commit
5be36ab First commit

--graph --decorate

Branch execution paths పక్కన branch labels (HEAD, branch names, tags)తో ASCII-art representationను గీస్తుంది.

$ git log --graph --oneline --decorate --all
*   6df8d03 (HEAD -> main) Merge feature branch
|\
| * c4f8101 (feature) Feature commit
* | ae39f81 Second commit
|/
* 5be36ab First commit

Custom formats (--pretty=format:)

Placeholders ఉపయోగించి మీకు నచ్చిన output templatesను రూపొందించవచ్చు. ఉదాహరణకు, hash, author name, date, commit message మాత్రమే print చేయడానికి:

$ git log --pretty=format:"%h - %an (%ar): %s"
6df8d03 - Purna Pattela (2 minutes ago): Merge feature branch
c4f8101 - Purna Pattela (5 minutes ago): Feature commit

ముఖ్యమైన placeholders:

  • %h: Abbreviated commit hash.
  • %an: Author name.
  • %ar: Author date (relative, ఉదా. “3 days ago”).
  • %ad: Author date (absolute format).
  • %s: Subject line (commit messageలోని మొదటి line).
  • %d: Ref decorations (ఉదా. (HEAD -> main)).

2. ఫోరెన్సిక్ చరిత్ర ఫిల్టరింగ్

Code changesతో search చేయడం (Pickaxe -S)

మీ codebaseలోని ఒక నిర్దిష్ట text string (ఉదా. function name లేదా API endpoint)ను ఏ commit చేర్చిందో లేదా తొలగించిందో తెలుసుకోవాలంటే -S flag ఉపయోగించండి:

$ git log -S "payment_processor_v2" --oneline

దీనినే Pickaxe అంటారు. ఇది కేవలం commit message textను search చేయదు; ప్రతి commit stateలో filesలోని contentsను search చేస్తుంది.

Commit messageతో search చేయడం (--grep)

ఒక keyword కోసం commit messagesలో మాత్రమే search చేయడానికి:

$ git log --grep="bugfix"

Pathతో filter చేయడం

నిర్దిష్ట file లేదా folderను మార్చిన commitsను మాత్రమే చూడటానికి double-dash తర్వాత file pathను జోడించండి:

$ git log --oneline -- src/utils/helper.js

నిజ జీవిత పరిస్థితి: Regressionను debug చేయడం

మీ team application యొక్క కొత్త versionను deploy చేసిందని, users “Submit” button click చేసినప్పుడు application crash అవుతోందని చెబుతున్నారని ఊహించండి. ఒక వారం క్రితం button బాగానే పనిచేసిందని మీకు తెలుసు.

కారణమైన commitను కనుగొనడానికి history filtersను కలిపి ఉపయోగించవచ్చు:

# Step 1: List all commits from the last week that modified the checkout button component
$ git log --since="1 week ago" --oneline -- src/components/SubmitButton.js
a3d5f9c refactor: rewrite submit click handler
54f8b9e chore: update button styling

# Step 2: Show the actual code modifications in the suspicious commit (a3d5f9c)
$ git log -p -1 a3d5f9c

Patch flag -p ఉపయోగించి handler functionలోని exact changesను పరిశీలిస్తే, missing event parameter కనిపిస్తుంది; ఆపై hotfix రాయవచ్చు.


సాధారణ ఇబ్బందులు మరియు తప్పులు

1. Pagerలో చిక్కుకుపోవడం

Defaultగా, log output మీ screen heightకంటే పొడవుగా ఉంటే Git outputను pager utilityకి (సాధారణంగా less) పంపుతుంది. Normal terminalకు ఎలా తిరిగి రావాలో beginnersకు తరచూ తెలియదు.

  • పరిష్కారం: Pager నుంచి బయటకు రావడానికి q నొక్కండి.
  • చిట్కా: Pager తెరవకుండా outputను నేరుగా terminalలో print చేయాలంటే pager configను catగా సెట్ చేయండి:
$ git --no-pager log -n 5

2. ఇతర branchesలోని commits కనిపించకపోవడం

git log మీ ప్రస్తుత branch history నుంచి reachableగా ఉన్న commitsనే చూపిస్తుంది. మీరు mainలో ఉండగా మరెవరైనా feature-bకి changes push చేస్తే, వారి commits మీకు కనిపించవు.

  • పరిష్కారం: అన్ని branchesలోని అన్ని commitsను చూపించడానికి --all flag ఉపయోగించండి:
$ git log --oneline --all --graph

3. git logను git reflogతో గందరగోళపరచడం

మీరు rebase (link git-rebase) లేదా reset commits చేస్తే, అవి branch history నుంచి తొలగిపోతాయి; ఇక git logలో కనిపించవు.

  • ఎందుకు: git log active pointersను మాత్రమే traverse చేస్తుంది.
  • పరిష్కారం: git reflog ఉపయోగించండి. Reference log మీ local machineలో HEAD pointerకు జరిగిన ప్రతి ఒక్క మార్పును (checkout switches, amends, resets, rebases సహా) track చేస్తుంది. “తొలగించిన” commitsను తిరిగి పొందడానికి ఇది మీకు అత్యంత నమ్మకమైన safety net.

కమాండ్ల త్వరిత సూచన

CommandAction
git logపూర్తి commit history (hashes, author, date, message) చూపిస్తుంది.
git log --onelineప్రతి commitకు compact, single-line summary చూపిస్తుంది.
git log --graph --oneline --allఅన్ని branches, mergesకు visual tree చూపిస్తుంది.
git log -pప్రతి commit ప్రవేశపెట్టిన patch (code diff) చూపిస్తుంది.
git log -n <limit>outputను పేర్కొన్న సంఖ్యలో commitsకు పరిమితం చేస్తుంది (ఉదా. -n 5).
git log --author="Name"author nameతో historyని filter చేస్తుంది.
git log --grep="pattern"messageలోని keywordsతో commitsను filter చేస్తుంది.
git log -S "code"నిర్దిష్ట code line/wordను చేర్చిన లేదా తొలగించిన commitsను కనుగొంటుంది.
git log --no-mergeshistory log నుంచి merge commitsను మినహాయిస్తుంది.

FAQ (తరచూ అడిగే ప్రశ్నలు)

git logలో నా commits ఎందుకు కనిపించడం లేదు?

మీరు ఇప్పుడే git commit నడిపినా అది logలో కనిపించకపోతే, ఇవి తనిఖీ చేయండి:

  1. Staging తనిఖీ: Commit చేయడానికి ముందు git add నడిపారా? నడపకపోతే ఏదీ staged కాకపోవడంతో commit reject అయి ఉండవచ్చు.
  2. Detached HEAD: మీరు detached HEAD stateలో ఉంటే మీ commits ఏ branchకూ associatedగా ఉండవు. mainను checkout చేస్తే అవి మీ log నుంచి మాయమైనట్టుగా కనిపిస్తాయి. కనిపించని hashesను కనుగొనడానికి git reflog నడపండి.

Author Date, Committer Date మధ్య తేడా ఏమిటి?

  • Author Date: Commit మొదట సృష్టించిన సమయం (ఉదా. git commit ఉపయోగించినప్పుడు).
  • Committer Date: Commit repositoryలో చివరిసారి రాసిన సమయం (ఉదా. cherry-pick, rebase లేదా amend చేసినప్పుడు).
  • Defaultగా git log Author Dateను చూపిస్తుంది. Committer Date చూడటానికి: git log --pretty=fuller.

ఒక fileలోని నిర్దిష్ట lineను ఎవరు మార్చారో ఎలా చూడాలి?

git log -S ఒక stringను చేర్చిన commitను కనుగొనగలదు; అయితే line-by-line authorship చూడటానికి git blame <file> వేగవంతమైన మార్గం. ఇది fileలోని ప్రతి lineకు commit hash, author name, timestamp చూపిస్తుంది.

నిర్దిష్ట date range కోసం commit historyలో ఎలా search చేయాలి?

మీరు --since (లేదా --after) మరియు --until (లేదా --before) flagsను కలిపి ఉపయోగించవచ్చు:

$ git log --since="2026-06-01" --until="2026-07-01" --oneline

Git relative human datesను కూడా parse చేస్తుంది; ఉదాహరణకు --since="3 weeks ago" లేదా --until="yesterday".


మీ జ్ఞానాన్ని పరీక్షించుకోండి

క్విజ్ లోడ్ అవుతోంది…