threads / discuss / 63645

Question: regarding understanding code base

Subject: Question: regarding understanding code base

## tl;dr

9 messages between Jun 14, 2025 and Jun 16, 2025.

replies: 8people: 3as markdown or json

JAYATHEERTH K· Jun 14, 2025, 12:43 UTC · lore

Ok so a couple of weeks ago, in this thread[1] Junio advised that one of the best ways to understand git is to go back to the _inital commit_ and travel back to the latest ones.

And I happened to quite like this idea, cause I still have to dig up a lot of things in git. The main question is What are the best and smallest set of git commands to do this as I can set this up as an alias and use this trick for many other projects too.

1 - https://lore.kernel.org/git/xmqqfrh3qe2w.fsf@gitster.g/
Thank you,
- Jayatheerth
Junio C Hamano· Jun 14, 2025, 15:43 UTC · re: JAYATHEERTH K · lore

Re: Question: regarding understanding code base

JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> writes:
> The main question is
> What are the best and smallest set of git commands to do this as
> I can set this up as an alias and use this trick for many other projects too.

Sorry, but I have no idea what you are trying to refer to as "this" in "commands to do this" and also "this" in "use this trick", so I cannot help you here.

JAYATHEERTH K· Jun 15, 2025, 00:24 UTC · re: Junio C Hamano · lore

Re: Question: regarding understanding code base

On Sat, Jun 14, 2025 at 9:13 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
>
> JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> writes:
>
> > The main question is
> > What are the best and smallest set of git commands to do this as
> > I can set this up as an alias and use this trick for many other projects too.
>
> Sorry, but I have no idea what you are trying to refer to as "this"
> in "commands to do this" and also "this" in "use this trick", so I
> cannot help you here.
>
>

What I meant was: You previously suggested that one good way to understand Git is to start from the initial commit of the Git repo and move forward chronologically through the commits.

I'd like to turn this approach into a repeatable workflow, possibly through an alias or small script.

So my question is: What is the smallest and most effective set of Git commands to:

- Start from the initial commit of a repository
- Walk forward through history (one commit at a time) probably which
changes my file system (I currently use a terminal based command)
I use
git rev-list --reverse HEAD | while read commit; do
  echo "=== Commit: $commit ==="
  git show --color --stat --patch --pretty=fuller "$commit"
  read -p "Press enter to continue to the next commit..."
done
I wanted to know if there are any better ways
Thanks again,
- Jayatheerth
Junio C Hamano· Jun 15, 2025, 00:43 UTC · re: JAYATHEERTH K · lore

Re: Question: regarding understanding code base

JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> writes:
> What I meant was:
> You previously suggested that one good way to understand Git is to
> start from the initial commit of the Git repo and move forward
> chronologically through the commits.

Not at all. I only suggested to study the initial one. It is more like biology students learning the common principles that apply to all kinds of life by studying a lot simpler organism as a model, instead of studying a lot higher order ones like mammals.

Moving forward is all your invention or hallucination ;-)
Show 13 quoted lines
> - Start from the initial commit of a repository
>
> - Walk forward through history (one commit at a time) probably which
> changes my file system (I currently use a terminal based command)
>
> I use
> git rev-list --reverse HEAD | while read commit; do
>   echo "=== Commit: $commit ==="
>   git show --color --stat --patch --pretty=fuller "$commit"
>   read -p "Press enter to continue to the next commit..."
> done
>
> I wanted to know if there are any better ways
Like "git log --reverse -p"?
JAYATHEERTH K· Jun 15, 2025, 00:48 UTC · re: Junio C Hamano · lore

Re: Question: regarding understanding code base

On Sun, Jun 15, 2025 at 6:13 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 15 quoted lines
>
> JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> writes:
>
> > What I meant was:
> > You previously suggested that one good way to understand Git is to
> > start from the initial commit of the Git repo and move forward
> > chronologically through the commits.
>
> Not at all.  I only suggested to study the initial one.  It is more
> like biology students learning the common principles that apply to
> all kinds of life by studying a lot simpler organism as a model,
> instead of studying a lot higher order ones like mammals.
>
> Moving forward is all your invention or hallucination ;-)
>

Fair enough I have read your biology metaphor into a full evolutionary theory.

Junio C Hamano· Jun 16, 2025, 00:40 UTC · re: JAYATHEERTH K · lore

Re: Question: regarding understanding code base

JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> writes:
Show 18 quoted lines
> On Sun, Jun 15, 2025 at 6:13 AM Junio C Hamano <gitster@pobox.com> wrote:
>>
>> JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> writes:
>>
>> > What I meant was:
>> > You previously suggested that one good way to understand Git is to
>> > start from the initial commit of the Git repo and move forward
>> > chronologically through the commits.
>>
>> Not at all.  I only suggested to study the initial one.  It is more
>> like biology students learning the common principles that apply to
>> all kinds of life by studying a lot simpler organism as a model,
>> instead of studying a lot higher order ones like mammals.
>>
>> Moving forward is all your invention or hallucination ;-)
>>
> Fair enough I have read your biology metaphor
> into a full evolutionary theory.

I should probably have said "before" instead of "instead of" in the above. You were looking for a way to see what higher order organisms there are to study, after learning from the simplest organism.

"git log --reverse -p" is a simpler replacement for your shell script loop to do so.

If I were doing this, after studying the initial one, I would probably see how much of what I learned from the initial version remains in 1.0.0, 1.3.0, 1.5.3, and 1.6.0.

1.5.3 was probably the last version one can read cover to cover in one sitting. Anything after that version are just too big, I think, but there probably are those with more patience than I have ;-).

JAYATHEERTH K· Jun 16, 2025, 09:44 UTC · re: Junio C Hamano · lore

Re: Question: regarding understanding code base

On Mon, Jun 16, 2025 at 6:10 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 37 quoted lines
>
> JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> writes:
>
> > On Sun, Jun 15, 2025 at 6:13 AM Junio C Hamano <gitster@pobox.com> wrote:
> >>
> >> JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> writes:
> >>
> >> > What I meant was:
> >> > You previously suggested that one good way to understand Git is to
> >> > start from the initial commit of the Git repo and move forward
> >> > chronologically through the commits.
> >>
> >> Not at all.  I only suggested to study the initial one.  It is more
> >> like biology students learning the common principles that apply to
> >> all kinds of life by studying a lot simpler organism as a model,
> >> instead of studying a lot higher order ones like mammals.
> >>
> >> Moving forward is all your invention or hallucination ;-)
> >>
> > Fair enough I have read your biology metaphor
> > into a full evolutionary theory.
>
> I should probably have said "before" instead of "instead of" in the
> above.  You were looking for a way to see what higher order
> organisms there are to study, after learning from the simplest
> organism.
>
> "git log --reverse -p" is a simpler replacement for your shell
> script loop to do so.
>
> If I were doing this, after studying the initial one, I would
> probably see how much of what I learned from the initial version
> remains in 1.0.0, 1.3.0, 1.5.3, and 1.6.0.
>
> 1.5.3 was probably the last version one can read cover to cover in
> one sitting.  Anything after that version are just too big, I think,
> but there probably are those with more patience than I have ;-).
Agreed, it takes time to sincerely understand each function

Till now how I've done is Whenever there was a bug report I acted like the compiler, tracing the file and function with pen and paper and found the quirk While this would work for bug fixes, I'm not sure if this is a good practice for big projects or a good practice in general.

Ben Knoble· Jun 15, 2025, 00:26 UTC · re: JAYATHEERTH K · lore

Re: Question: regarding understanding code base

Show 11 quoted lines
> Le 14 juin 2025 à 08:44, JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> a écrit :
> 
> Ok so a couple of weeks ago, in this thread[1]
> Junio advised that one of the best ways to understand git is to go back to the
> _inital commit_ and travel back to the latest ones.
> 
> And I happened to quite like this idea, cause I still have to dig up a
> lot of things in git.
> The main question is
> What are the best and smallest set of git commands to do this as
> I can set this up as an alias and use this trick for many other projects too.
If you want a checkout of the root commit, assuming there’s only one, something like
    git rev-list | sed -n \$p | xargs git switch --detach
ought to work. You could feed something similar to git-worktree. But it’s a little harder to “go forward” with Git’s data model, and I didn’t totally understand “travel back to the latest ones.”
Show 8 quoted lines
> 
> 1 - https://lore.kernel.org/git/xmqqfrh3qe2w.fsf@gitster.g/
> 
> 
> Thank you,
> 
> - Jayatheerth
> 
JAYATHEERTH K· Jun 15, 2025, 00:37 UTC · re: Ben Knoble · lore

Re: Question: regarding understanding code base

On Sun, Jun 15, 2025 at 5:56 AM Ben Knoble <ben.knoble@gmail.com> wrote:
Show 20 quoted lines
>
>
> > Le 14 juin 2025 à 08:44, JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com> a écrit :
> >
> > Ok so a couple of weeks ago, in this thread[1]
> > Junio advised that one of the best ways to understand git is to go back to the
> > _inital commit_ and travel back to the latest ones.
> >
> > And I happened to quite like this idea, cause I still have to dig up a
> > lot of things in git.
> > The main question is
> > What are the best and smallest set of git commands to do this as
> > I can set this up as an alias and use this trick for many other projects too.
>
> If you want a checkout of the root commit, assuming there’s only one, something like
>
>     git rev-list | sed -n \$p | xargs git switch --detach
>
> ought to work. You could feed something similar to git-worktree. But it’s a little harder to “go forward” with Git’s data model, and I didn’t totally understand “travel back to the latest ones.”
>

By _travel back to the latest ones_ I think I should have said travel _forward to the latest ones_

But I meant to incrementally get to the _latest commit_ from the _initial commit_

← back to recent threads