Files
git-practice-Mag/ASSIGNMENT-04-09-2025.md
2025-09-11 05:56:47 +00:00

9.0 KiB

Part 1: Viewing File History

Clone any public GitHub repository or create a new one.

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~ (master)
$ mkdir git-assignment-3

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~ (master)
$ cd git-assignment-3

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git init
Initialized empty Git repository in C:/Users/Magdel/git-assignment-3/.git/

Make a few commits modifying the same file (e.g., example.txt).

### Creating file
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ echo "Version 0" > example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git add example.txt
warning: in the working copy of 'example.txt', LF will be replaced by CRLF the next time Git touches it

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git commit -m "Creating a file and adding text"
[master (root-commit) c542401] Creating a file and adding text
 1 file changed, 1 insertion(+)
### overwrite new file with different text
Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git add example.txt
warning: in the working copy of 'example.txt', LF will be replaced by CRLF the next time Git touches it

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git commit -m "New text"
[master adfd713] New text
 1 file changed, 1 insertion(+), 1 deletion(-)
### add text
 Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ echo "New line of text" >> example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git commit -am "V1 text"
warning: in the working copy of 'example.txt', LF will be replaced by CRLF the next time Git touches it
[master 5cbabdb] V1 text
 1 file changed, 1 insertion(+)

Run the following commands and note down the output:
git log -- example.txt git log -p -- example.txt git log --oneline -- example.txt

Outputs

git log -- example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git log -- example.txt
commit 5cbabdbd373303a526d5bf59a986681c1d44f112 (HEAD -> master)
Author: Magdel <raokhshna.m@comorin.co>
Date:   Thu Sep 11 10:22:06 2025 +0530

    V1 text

commit adfd71368aeeebb2e8e8a01f8ea046666c1ca348
Author: Magdel <raokhshna.m@comorin.co>
Date:   Thu Sep 11 10:20:28 2025 +0530

    New text

commit c53de287fd845eeb462ebff6e3ae6c5d201891f2
Author: Magdel <raokhshna.m@comorin.co>
Date:   Thu Sep 11 10:14:10 2025 +0530

    Create new file and add text

git log -p -- example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git log -p -- example.txt
commit 5cbabdbd373303a526d5bf59a986681c1d44f112 (HEAD -> master)
Author: Magdel <raokhshna.m@comorin.co>
Date:   Thu Sep 11 10:22:06 2025 +0530

    V1 text

diff --git a/example.txt b/example.txt
index fb8247c..2d54dc0 100644
--- a/example.txt
+++ b/example.txt
@@ -1 +1,2 @@
 Version 1
+New line of text

commit adfd71368aeeebb2e8e8a01f8ea046666c1ca348
Author: Magdel <raokhshna.m@comorin.co>
Date:   Thu Sep 11 10:20:28 2025 +0530

    New text

diff --git a/example.txt b/example.txt
index 8dc77ab..fb8247c 100644
--- a/example.txt
+++ b/example.txt
@@ -1 +1,2 @@
 Version 1
+New line of text

commit adfd71368aeeebb2e8e8a01f8ea046666c1ca348
Author: Magdel <raokhshna.m@comorin.co>
Date:   Thu Sep 11 10:20:28 2025 +0530

    New text

diff --git a/example.txt b/example.txt
index 8dc77ab..fb8247c 100644
--- a/example.txt
+++ b/example.txt
@@ -1 +1 @@
-Version 0
+Version 1

commit c53de287fd845eeb462ebff6e3ae6c5d201891f2
Author: Magdel <raokhshna.m@comorin.co>
Date:   Thu Sep 11 10:14:10 2025 +0530

    Create new file and add text

diff --git a/example.txt b/example.txt
new file mode 100644
index 0000000..8dc77ab
--- /dev/null
+++ b/example.txt
@@ -0,0 +1 @@
+Version 0

git log --oneline -- example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git log --oneline -- example.txt
5cbabdb (HEAD -> master) V1 text
adfd713 New text
c53de28 Create new file and add text

Questions to answer in your notes:

How many commits modified this file?
There are 3 commits overall, 2 commit that modified example.txt. 
Commit 1 - c53de28 - "Create new file and add text" 
Commit 2 - adfd713 - "New text"
Commit 3 - 5cbabdb - "V1 text"
Commit 2 and Commit 3 modified the initial commit 1
What differences do you see when adding the -p option?
Commit 2: adfd713 changes content from "Version 0" to "Version 1"
Commit 3: 5cbabdbd modified example.txt further from Commit 2: adfd713 by adding a new line of text ie: "New line of text"

Part 2: Viewing File History with Blame

Edit the file example.txt by adding several lines in multiple commits

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ echo "Title" > example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git commit -am "add title"
warning: in the working copy of 'git-assignment-3/example.txt', LF will be replaced by CRLF the next time Git touches it
[master 7cb8341] add title
 1 file changed, 1 insertion(+), 1 deletion(-)

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ echo "Heading 1" >> example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git commit -am "First heading"
warning: in the working copy of 'git-assignment-3/example.txt', LF will be replaced by CRLF the next time Git touches it
[master 08aefdc] First heading
 1 file changed, 1 insertion(+)

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ echo "This is the first paragraph in this section" >> example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git commit -am "Add paragraph"
warning: in the working copy of 'git-assignment-3/example.txt', LF will be replaced by CRLF the next time Git touches it
[master 1c07bef] Add paragraph
 1 file changed, 1 insertion(+)

Use the following commands: git blame example.txt git blame -L 1,5 example.txt git blame -e example.txt

git blame example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git blame example.txt
7cb83413 (Magdel 2025-09-11 11:06:51 +0530 1) Title
08aefdcf (Magdel 2025-09-11 11:07:19 +0530 2) Heading 1
1c07bef9 (Magdel 2025-09-11 11:08:32 +0530 3) This is the first paragraph in this section

git blame -L 1.5 example.txt

$ git blame -L 1,5 example.txt
7cb83413 (Magdel 2025-09-11 11:06:51 +0530 1) Title
08aefdcf (Magdel 2025-09-11 11:07:19 +0530 2) Heading 1
1c07bef9 (Magdel 2025-09-11 11:08:32 +0530 3) This is the first paragraph in this section

git blame -e example.txt

$ git blame -e example.txt
7cb83413 (<raokhshna.m@comorin.co> 2025-09-11 11:06:51 +0530 1) Title
08aefdcf (<raokhshna.m@comorin.co> 2025-09-11 11:07:19 +0530 2) Heading 1
1c07bef9 (<raokhshna.m@comorin.co> 2025-09-11 11:08:32 +0530 3) This is the first paragraph in this section

Questions to answer in your notes:

Who changed each line of the file?
Magdel
How does -L help when the file is large?
-L limits the results by line range provided. In this case Lines 1 through 5.
What extra information does -e provide?
It add the Author's email address for a specific commit/addition.

Part 3: Merging Branches

Create and switch to a new branch: git checkout -b feature/feature-1

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git checkout -b feature/feature-1
Switched to a new branch 'feature/feature-1'

Modify example.txt and commit the change.

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (feature/feature-1)
$ echo "Feature branch change" >> example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (feature/feature-1)
$ git commit -am "Update from feature branch"
warning: in the working copy of 'git-assignment-3/example.txt', LF will be replaced by CRLF the next time Git touches it
[feature/feature-1 17db618] Update from feature branch
 1 file changed, 1 insertion(+)

Switch back to main branch and modify the same file in a different way, then commit.

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (feature/feature-1)
$ git checkout master
Switched to branch 'master'

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ echo "Main branch change" >> example.txt

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git commit -am "New Update from Main branch"
warning: in the working copy of 'git-assignment-3/example.txt', LF will be replaced by CRLF the next time Git touches it
[master 4e58622] New Update from Main branch
 1 file changed, 1 insertion(+)

Merge feature/feature-1 into main:

git merge feature/feature-1

Magdel@LAPTOP-NS5FVUS9 MINGW64 ~/git-assignment-3 (master)
$ git merge feature/feature-1
Auto-merging git-assignment-3/example.txt
CONFLICT (content): Merge conflict in git-assignment-3/example.txt
Automatic merge failed; fix conflicts and then commit the result.

Questions to answer in your notes:

Did Git perform a fast-forward merge or a 3-way merge?
What does git log --graph --oneline --all show after the merge?