Search code examples
gitgit-commit

Does a new commit include changes from old commit?


Lets say I have a local repository named 'ABC" having a text file. I add 2 lines to the text file, and commit it. Lets call it "Commit A". Then I add 2 more lines to it and commit it. Lets call it "Commit B".

Will Commit B have the original text in text file and all the 4 new lines added, or just the 2 lines added in Commit B?

If I branch from Commit B, will the new branch have the original text and the 4 lines added, or just the 2 lines added in Commit B?


Solution

  • In layman terms, a commit is like a change set or a snapshot of your repo. Please check this answer for more details.

    In your example, when you checkout a branch from Commit B, the branch will have commit B and its all past commits. Hence the new branch will have original text and 4 lines added.