From 63d411e23064d02110cf918dac769b9e6f28a0ce Mon Sep 17 00:00:00 2001 From: D3LET3-57 Date: Tue, 3 Jun 2025 11:18:08 +0530 Subject: [PATCH 1/7] Solution for Assignment 1 --- Lalith/Assignment_1/README.md | 363 ++++++++++++++++++++++++++++++++++ 1 file changed, 363 insertions(+) create mode 100644 Lalith/Assignment_1/README.md diff --git a/Lalith/Assignment_1/README.md b/Lalith/Assignment_1/README.md new file mode 100644 index 0000000..3096c2f --- /dev/null +++ b/Lalith/Assignment_1/README.md @@ -0,0 +1,363 @@ +# My solutions for Bandit - OverTheWire.org +## Bandit Level 0 + +```bash +ssh bandit0@bandit.labs.overthewire.org -p 2220 +``` +Connect to the server using the provided command. The password is `bandit0`. +Password for Bandit Level 1 is found in the file `readme` in the home directory of Bandit Level 0. +Password: `ZjLjTmM6FvvyRnrb2rfNWOZOTa6ip5If` + +## Bandit Level 1 + +```bash +bandit1@bandit:~$ cat /home/bandit1/- +263JGJPfgU6LtdEvgfWU1XP5yac29mFx +``` +Password for Bandit Level 2 is found in the file `-` in the home directory of Bandit Level 1. +Password: `263JGJPfgU6LtdEvgfWU1XP5yac29mFx` + +## Bandit Level 2 + +```bash +bandit2@bandit:~$ cat spaces\ in\ this\ filename +MNk8KNH3Usiio41PRUEoDFPqfxLPlSmx +``` +Password for Bandit Level 3 is found in the file `spaces in this filename` in the home directory of Bandit Level 2. + +Password: `MNk8KNH3Usiio41PRUEoDFPqfxLPlSmx` + +## Bandit Level 3 + +```bash +bandit3@bandit:~/inhere$ ls -la +total 12 +drwxr-xr-x 2 root root 4096 Apr 10 14:23 . +drwxr-xr-x 3 root root 4096 Apr 10 14:23 .. +-rw-r----- 1 bandit4 bandit3 33 Apr 10 14:23 ...Hiding-From-You +bandit3@bandit:~/inhere$ cat ...Hiding-From-You +2WmrDFRmJIq3IPxneAaMGhap0pFhF3NJ +``` +Password for Bandit Level 4 is found in the file `...Hiding-From-You` in the home directory of Bandit Level 3. +Password: `2WmrDFRmJIq3IPxneAaMGhap0pFhF3NJ` + +## Bandit Level 4 + We will use the file command to get the information about the files. From files command, we now know that the file07 contains ASCII text +```bash +bandit4@bandit:~/inhere$ file ./* +./-file00: PGP Secret Sub-key - +./-file01: data +./-file02: data +./-file03: data +./-file04: data +./-file05: data +./-file06: data +./-file07: ASCII text +./-file08: data +./-file09: data +bandit4@bandit:~/inhere$ cat ./-file07 +4oQYVPkxZOOEOO5pTW81FB8j8lxXGUQw +``` +Password: `4oQYVPkxZOOEOO5pTW81FB8j8lxXGUQw` + +## Bandit Level 5 + +```bash +bandit5@bandit:~/inhere$ find . -size 1033c +./maybehere07/.file2 +bandit5@bandit:~/inhere$ cat ./maybehere07/.file2 +HWasnPhtq9AVKe0dmk45nxy20cvUa6EG +``` +Used `-size` flag to find the file with size 1033 bytes. The file is located in `maybehere07` directory +Password: `HWasnPhtq9AVKe0dmk45nxy20cvUa6EG` + +## Bandit Level 6 + +```bash +bandit6@bandit:~$ find / -user bandit7 -group bandit6 -size 33c +/var/lib/dpkg/info/bandit7.password +bandit6@bandit:~$ cat /var/lib/dpkg/info/bandit7.password +morbNTDkSW6jIlUc0ymOdMaLnOlFVAaj +``` +Used the `find` command to locate files owned by user `bandit7` and group `bandit6` with a size of 33 bytes, starting from the root directory. The password file was found at `/var/lib/dpkg/info/bandit7.password`. +Password: `morbNTDkSW6jIlUc0ymOdMaLnOlFVAaj` +## Bandit Level 7 + +```bash +bandit7@bandit:~$ ls +data.txt +bandit7@bandit:~$ file data.txt +data.txt: Unicode text, UTF-8 text +bandit7@bandit:~$ cat data.txt | grep "millionth" +millionth dfwvzFQi4mU0wfNbFOe9RoWskMLg7eEc +bandit7@bandit:~$ +``` +Used the `file` command to check the type of `data.txt`, which revealed it was a Unicode text file. Then, used `grep` to search for the string "millionth" in the file, which returned the password. +Password: `dfwvzFQi4mU0wfNbFOe9RoWskMLg7eEc` + +## Bandit Level 8 + +```bash +bandit8@bandit:~$ file data.txt +data.txt: ASCII text +bandit8@bandit:~$ cat data.txt | sort |less +bandit8@bandit:~$ cat data.txt | sort | uniq -u +4CKMh1JI91bUIZZPXDqGanal4xvAg0JM +``` +Used the `file` command to check the type of `data.txt`, which revealed it was an ASCII text file. Then, used `sort` to order the lines, and `uniq -u` to print only the unique line (the password). The `-u` option ensures only lines that appear exactly once are shown, filtering out any duplicates. +Password: `4CKMh1JI91bUIZZPXDqGanal4xvAg0JM` +## Bandit Level 9 + +```bash +bandit9@bandit:~$ file data.txt +data.txt: data +bandit9@bandit:~$ cat data.txt | grep "====" +grep: (standard input): binary file matches +bandit9@bandit:~$ strings data.txt | grep "==" +========== the +========== password{k +=========== is +========== FGUW5ilLVJrxX9kMYMmlN4MgbpfMiqey +``` +Used the `file` command to check the type of `data.txt`, which revealed it was a binary file. Then, used `strings` to extract printable strings from the binary file and `grep` to search for lines containing "==". This returned the password. +Password: `FGUW5ilLVJrxX9kMYMmlN4MgbpfMiqey` +## Bandit Level 10 + +```bash +bandit10@bandit:~$ cat data.txt +VGhlIHBhc3N3b3JkIGlzIGR0UjE3M2ZaS2IwUlJzREZTR3NnMlJXbnBOVmozcVJyCg== +bandit10@bandit:~$ cat data.txt | base64 --decode +The password is dtR173fZKb0RRsDFSGsg2RWnpNVj3qRr +``` +Used `base64 --decode` to decode the base64 encoded string in `data.txt`, which revealed the password. +Password: `dtR173fZKb0RRsDFSGsg2RWnpNVj3qRr` +## Bandit Level 11 + +```bash +bandit11@bandit:~$ cat data.txt +Gur cnffjbeq vf 7k16JArUVv5LxVuJfsSVdbbtaHGlw9D4 +``` +Used an online ROT13 decoder to decode the string in `data.txt`, which revealed the password. +Password: `7x16WNeHIi5YkIhWsfFIqoognUTyj9Q4` +## Bandit Level 12 + +```bash +bandit12@bandit:~$ mkdir /tmp/d3let3 +bandit12@bandit:~$ cp data.txt /tmp/d3let3 +bandit12@bandit:~$ cd /tmp/d3let3 +bandit12@bandit:/tmp/d3let3$ ls +data.txt +bandit12@bandit:/tmp/d3let3$ xxd -r data.txt data +bandit12@bandit:/tmp/d3let3$ gzip -d data +gzip: data: unknown suffix -- ignored +bandit12@bandit:/tmp/d3let3$ mv data txt.gz +bandit12@bandit:/tmp/d3let3$ gzip -d txt.gz +bandit12@bandit:/tmp/d3let3$ cat txt +bandit12@bandit:/tmp/d3let3$ file txt +txt: bzip2 compressed data, block size = 900k +bandit12@bandit:/tmp/d3let3$ mv txt txxt.bz2 +bandit12@bandit:/tmp/d3let3$ bzip2 -d txxt.bz2 +bandit12@bandit:/tmp/d3let3$ file txxt +txxt: gzip compressed data, was "data4.bin", last modified: Thu Apr 10 14:22:57 2025, max compression, from Unix, original size modulo 2^32 20480 +bandit12@bandit:/tmp/d3let3$ mv txxt d4ta.gz +bandit12@bandit:/tmp/d3let3$ gzip -d d4ta.gz +bandit12@bandit:/tmp/d3let3$ file d4ta +d4ta: POSIX tar archive (GNU) +bandit12@bandit:/tmp/d3let3$ tar -xvf d4ta +data5.bin +bandit12@bandit:/tmp/d3let3$ file data5.bin +data5.bin: POSIX tar archive (GNU) +bandit12@bandit:/tmp/d3let3$ tar -xvf data5.bin +data6.bin +bandit12@bandit:/tmp/d3let3$ file data6.bin +data6.bin: bzip2 compressed data, block size = 900k +bandit12@bandit:/tmp/d3let3$ mv data6.bin data6.bz +bandit12@bandit:/tmp/d3let3$ bzip -d data6.bz +Command 'bzip' not found, but there are 21 similar ones. +bandit12@bandit:/tmp/d3let3$ bzip2 -d data6.bz +bandit12@bandit:/tmp/d3let3$ file data6 +data6: POSIX tar archive (GNU) +bandit12@bandit:/tmp/d3let3$ tar -xvf data6 +data8.bin +bandit12@bandit:/tmp/d3let3$ file data8.bin +data8.bin: gzip compressed data, was "data9.bin", last modified: Thu Apr 10 14:22:57 2025, max compression, from Unix, original size modulo 2^32 49 +bandit12@bandit:/tmp/d3let3$ mv data8.bin data8.gz +bandit12@bandit:/tmp/d3let3$ gzip -d data8.gz +bandit12@bandit:/tmp/d3let3$ file data8 +data8: ASCII text +bandit12@bandit:/tmp/d3let3$ cat data8 +The password is FO5dwFsc0cbaIiH0h8J2eUks2vdTDwAn +``` +Used a series of commands to decode and extract the password from the file `data.txt`. The process involved creating a temporary directory, copying the file, using `xxd` to reverse the hex dump, decompressing with `gzip`, renaming files, and finally extracting the password from the last file. +Password: `FO5dwFsc0cbaIiH0h8J2eUks2vdTDwAn` +## Bandit Level 13 + +```bash +bandit13@bandit:~$ ssh -i sshkey.private -p 2220 bandit14@localhost +bandit14@bandit:~$ cat /etc/bandit_pass/bandit14 +MU4VWeTyJk8ROof1qqmcBPaLh7lDCPvS +``` +Used the private SSH key `sshkey.private` to connect to Bandit Level 14. The password for Bandit Level 14 is found in the file `/etc/bandit_pass/bandit14`. +Password: `MU4VWeTyJk8ROof1qqmcBPaLh7lDCPvS` + +## Bandit Level 14 + +```bash +bandit14@bandit:~$ nc localhost 30000 +MU4VWeTyJk8ROof1qqmcBPaLh7lDCPvS +Correct! +8xCjnmgoKbGLhHFAZlGE5Tmu4M2tKJQo + +^C +bandit14@bandit:~$ +``` +Used `nc` (netcat) to connect to localhost on port 30000. The server prompts for the password, which is the same as the previous level's password. After entering the correct password, it returns the new password. +Password: `8xCjnmgoKbGLhHFAZlGE5Tmu4M2tKJQo` + +## Bandit Level 15 + +```bash +bandit15@bandit:~$ openssl s_client -connect localhost:30001 +CONNECTED(00000003) +Can't use SSL_get_servername +depth=0 CN = SnakeOil +verify error:num=18:self-signed certificate +verify return:1 +depth=0 CN = SnakeOil +verify return:1 +--- +Certificate chain + 0 s:CN = SnakeOil + i:CN = SnakeOil + a:PKEY: rsaEncryption, 4096 (bit); sigalg: RSA-SHA256 + v:NotBefore: Jun 10 03:59:50 2024 GMT; NotAfter: Jun 8 03:59:50 2034 GMT +--- +Server certificate +-----BEGIN CERTIFICATE----- +MIIFBzCCAu+gAwIBAgIUBLz7DBxA0IfojaL/WaJzE6Sbz7cwDQYJKoZIhvcNAQEL +BQAwEzERMA8GA1UEAwwIU25ha2VPaWwwHhcNMjQwNjEwMDM1OTUwWhcNMzQwNjA4 +MDM1OTUwWjATMREwDwYDVQQDDAhTbmFrZU9pbDCCAiIwDQYJKoZIhvcNAQEBBQAD +ggIPADCCAgoCggIBANI+P5QXm9Bj21FIPsQqbqZRb5XmSZZJYaam7EIJ16Fxedf+ +jXAv4d/FVqiEM4BuSNsNMeBMx2Gq0lAfN33h+RMTjRoMb8yBsZsC063MLfXCk4p+ +09gtGP7BS6Iy5XdmfY/fPHvA3JDEScdlDDmd6Lsbdwhv93Q8M6POVO9sv4HuS4t/ +jEjr+NhE+Bjr/wDbyg7GL71BP1WPZpQnRE4OzoSrt5+bZVLvODWUFwinB0fLaGRk +GmI0r5EUOUd7HpYyoIQbiNlePGfPpHRKnmdXTTEZEoxeWWAaM1VhPGqfrB/Pnca+ +vAJX7iBOb3kHinmfVOScsG/YAUR94wSELeY+UlEWJaELVUntrJ5HeRDiTChiVQ++ +wnnjNbepaW6shopybUF3XXfhIb4NvwLWpvoKFXVtcVjlOujF0snVvpE+MRT0wacy +tHtjZs7Ao7GYxDz6H8AdBLKJW67uQon37a4MI260ADFMS+2vEAbNSFP+f6ii5mrB +18cY64ZaF6oU8bjGK7BArDx56bRc3WFyuBIGWAFHEuB948BcshXY7baf5jjzPmgz +mq1zdRthQB31MOM2ii6vuTkheAvKfFf+llH4M9SnES4NSF2hj9NnHga9V08wfhYc +x0W6qu+S8HUdVF+V23yTvUNgz4Q+UoGs4sHSDEsIBFqNvInnpUmtNgcR2L5PAgMB +AAGjUzBRMB0GA1UdDgQWBBTPo8kfze4P9EgxNuyk7+xDGFtAYzAfBgNVHSMEGDAW +gBTPo8kfze4P9EgxNuyk7+xDGFtAYzAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3 +DQEBCwUAA4ICAQAKHomtmcGqyiLnhziLe97Mq2+Sul5QgYVwfx/KYOXxv2T8ZmcR +Ae9XFhZT4jsAOUDK1OXx9aZgDGJHJLNEVTe9zWv1ONFfNxEBxQgP7hhmDBWdtj6d +taqEW/Jp06X+08BtnYK9NZsvDg2YRcvOHConeMjwvEL7tQK0m+GVyQfLYg6jnrhx +egH+abucTKxabFcWSE+Vk0uJYMqcbXvB4WNKz9vj4V5Hn7/DN4xIjFko+nREw6Oa +/AUFjNnO/FPjap+d68H1LdzMH3PSs+yjGid+6Zx9FCnt9qZydW13Miqg3nDnODXw ++Z682mQFjVlGPCA5ZOQbyMKY4tNazG2n8qy2famQT3+jF8Lb6a4NGbnpeWnLMkIu +jWLWIkA9MlbdNXuajiPNVyYIK9gdoBzbfaKwoOfSsLxEqlf8rio1GGcEV5Hlz5S2 +txwI0xdW9MWeGWoiLbZSbRJH4TIBFFtoBG0LoEJi0C+UPwS8CDngJB4TyrZqEld3 +rH87W+Et1t/Nepoc/Eoaux9PFp5VPXP+qwQGmhir/hv7OsgBhrkYuhkjxZ8+1uk7 +tUWC/XM0mpLoxsq6vVl3AJaJe1ivdA9xLytsuG4iv02Juc593HXYR8yOpow0Eq2T +U5EyeuFg5RXYwAPi7ykw1PW7zAPL4MlonEVz+QXOSx6eyhimp1VZC11SCg== +-----END CERTIFICATE----- +subject=CN = SnakeOil +issuer=CN = SnakeOil +--- +No client certificate CA names sent +Peer signing digest: SHA256 +Peer signature type: RSA-PSS +Server Temp Key: X25519, 253 bits +--- +SSL handshake has read 2103 bytes and written 373 bytes +Verification error: self-signed certificate +--- +New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384 +Server public key is 4096 bit +Secure Renegotiation IS NOT supported +Compression: NONE +Expansion: NONE +No ALPN negotiated +Early data was not sent +Verify return code: 18 (self-signed certificate) +--- +--- +Post-Handshake New Session Ticket arrived: +SSL-Session: + Protocol : TLSv1.3 + Cipher : TLS_AES_256_GCM_SHA384 + Session-ID: 68C81752B64BEF2EDBEEE104C3E43CE1A85B8CED5573A2621DF10DD4BB4E026A + Session-ID-ctx: + Resumption PSK: D5EE94BABC7C01AF9FAAD92CD58927794DCB1661BD92F968F4AC11C87751F3B5DCECA5598C3828167F69241A98F23452 + PSK identity: None + PSK identity hint: None + SRP username: None + TLS session ticket lifetime hint: 300 (seconds) + TLS session ticket: + 0000 - 90 26 4b 61 3e 89 95 1a-4b 9c 04 1b 5a 25 70 8d .&Ka>...K...Z%p. + 0010 - 9b e7 47 fc b3 e2 2a fd-e2 be 05 14 24 01 28 0d ..G...*.....$.(. + 0020 - e0 c4 33 a6 fc 30 ce d7-f1 b1 36 37 00 90 a8 26 ..3..0....67...& + 0030 - a0 8e 8a eb 20 9c 19 fb-ba 08 85 c4 b9 cc 0c e0 .... ........... + 0040 - cc a9 7b f1 1c 73 65 35-dc 97 66 20 9e d3 76 20 ..{..se5..f ..v + 0050 - f0 29 04 21 6e c3 26 b6-10 db 1d be 9d 1d 8f b4 .).!n.&......... + 0060 - bd cd 71 03 f9 d8 4a ae-9f ff f2 66 d7 e3 26 a2 ..q...J....f..&. + 0070 - 81 8a 59 ec d4 1f 2c d7-43 63 58 cf 51 fc fe 5b ..Y...,.CcX.Q..[ + 0080 - 0e 7d 67 42 52 01 36 20-cc 18 4c 72 cc 94 91 1f .}gBR.6 ..Lr.... + 0090 - 61 d8 3b 49 6a 93 ef 43-19 61 af 74 7a 09 51 8c a.;Ij..C.a.tz.Q. + 00a0 - 0b ea 02 b5 28 08 f1 a9-57 5a 0c 7a 96 1d a8 19 ....(...WZ.z.... + 00b0 - f3 ab fc ef 25 e9 f1 99-f4 7f e4 a9 46 84 4b 76 ....%.......F.Kv + 00c0 - 3f 02 27 6e e4 a2 05 23-0f 00 ab d2 a3 46 54 b8 ?.'n...#.....FT. + 00d0 - fe 8a 5d 43 6e 4b a4 35-8b bd 3d 1d 0a 52 18 9b ..]CnK.5..=..R.. + + Start Time: 1748921757 + Timeout : 7200 (sec) + Verify return code: 18 (self-signed certificate) + Extended master secret: no + Max Early Data: 0 +--- +read R BLOCK +--- +Post-Handshake New Session Ticket arrived: +SSL-Session: + Protocol : TLSv1.3 + Cipher : TLS_AES_256_GCM_SHA384 + Session-ID: 406F9FED595D10EB429D57EB4CC0965D24E5355FBF5859C38E29C2BCEE4B5FF7 + Session-ID-ctx: + Resumption PSK: E5E19083A209E4154DEED6BC5E7C82F9548222E8ADDB491A5C273FA65CE7E70A7B3EAC6D4F2AF8594B4476BB423C096F + PSK identity: None + PSK identity hint: None + SRP username: None + TLS session ticket lifetime hint: 300 (seconds) + TLS session ticket: + 0000 - 90 26 4b 61 3e 89 95 1a-4b 9c 04 1b 5a 25 70 8d .&Ka>...K...Z%p. + 0010 - 78 23 7e 72 59 10 2d 55-07 81 d7 85 45 f5 9a c5 x#~rY.-U....E... + 0020 - ed fc e2 8c 1f 65 ce 69-c0 05 86 49 16 ac 16 64 .....e.i...I...d + 0030 - a3 bb 85 18 d3 03 e0 bc-32 39 7b 24 ec bd f4 47 ........29{$...G + 0040 - 58 9d e5 e9 83 89 84 fe-ab 22 d1 bb 3c 98 e2 03 X........"..<... + 0050 - d9 fc 2d 6c 1b 44 1c ed-c8 1f 3f 26 be 50 10 88 ..-l.D....?&.P.. + 0060 - cd f0 57 3e ae 14 f0 36-10 17 6b b6 01 69 46 11 ..W>...6..k..iF. + 0070 - 9e e2 07 3a c9 a0 0e 26-29 c3 2c 65 b8 3e 81 90 ...:...&).,e.>.. + 0080 - a4 18 59 65 8c c7 33 05-50 5e 09 8f 2a 12 90 c1 ..Ye..3.P^..*... + 0090 - 14 c8 39 9c ed 5f 73 dc-11 9e 7a d8 73 68 31 63 ..9.._s...z.sh1c + 00a0 - 90 68 53 b5 61 f4 bb f3-24 0d f1 4a c8 1e f8 e8 .hS.a...$..J.... + 00b0 - ff 98 93 b4 ab d2 66 9a-67 b0 a5 5f 77 f5 46 44 ......f.g.._w.FD + 00c0 - d9 c1 41 15 8c 9d 1d 62-a2 5f da 1e db ed ee 31 ..A....b._.....1 + 00d0 - cd 94 c8 b5 fd d7 12 16-20 d1 f5 84 bb 4f d2 f7 ........ ....O.. + + Start Time: 1748921757 + Timeout : 7200 (sec) + Verify return code: 18 (self-signed certificate) + Extended master secret: no + Max Early Data: 0 +--- +read R BLOCK +8xCjnmgoKbGLhHFAZlGE5Tmu4M2tKJQo +Correct! +kSkvUpMQ7lBYyCM4GBPvCvT1BfWRy0Dx + +closed +bandit15@bandit:~$ +``` +Used `openssl s_client` to connect to localhost on port 30001. The server presents a self-signed certificate, which is accepted despite the verification error. After entering the correct password, it returns the new password. +Password: `kSkvUpMQ7lBYyCM4GBPvCvT1BfWRy0Dx` From 964b5dd5a44c95a8d8bfae65a2732cd568a56020 Mon Sep 17 00:00:00 2001 From: D3LET3-57 Date: Tue, 3 Jun 2025 18:48:07 +0530 Subject: [PATCH 2/7] Assignment_2 solutions --- Lalith/Assignment_2/README.md | 779 ++++++++++++++++++++++++++++++++++ Lalith/Assignment_2/hello | 1 + 2 files changed, 780 insertions(+) create mode 100644 Lalith/Assignment_2/README.md create mode 160000 Lalith/Assignment_2/hello diff --git a/Lalith/Assignment_2/README.md b/Lalith/Assignment_2/README.md new file mode 100644 index 0000000..3fe47e5 --- /dev/null +++ b/Lalith/Assignment_2/README.md @@ -0,0 +1,779 @@ +# Lab 1 +I've already installed `ruby` and set up my git global config. +```console +user.name=D3LET3-57 +user.email=xxxxxxxxxxxxxxxxx@gmail.com +core.autocrlf=input +core.safecrlf=true +``` +# Lab 2 +No commands were run in this lab. + +# Lab 3 +```console +mkdir hello +cd hello +echo 'puts "Hello, World"' > hello.rb +cat hello.rb +git init +git add hello.rb +git commit -m "First Commit" +``` +I've created a new directory called `hello`, added a Ruby script that prints "Hello, World", and committed it to a new git repository. +# Lab 4 +```bash +➜ hello git:(master) git status +On branch master +nothing to commit, working tree clean +``` +Status shows that there are no changes to commit, and the working tree is clean. +# Lab 5 +```bash +➜ hello git:(master) echo 'puts "Hello, #{ARGV.first}!"' > hello.rb + +➜ hello git:(master) ✗ cat hello.rb +puts "Hello, #{ARGV.first}!" +➜ hello git:(master) ✗ git status +On branch master +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: hello.rb + +no changes added to commit (use "git add" and/or "git commit -a") +``` +I've modified the `hello.rb` file to accept an argument and print "Hello, {argument}!". The `git status` command shows that the file has been modified but not staged for commit. +# Lab 6 +```bash +➜ hello git:(master) ✗ git add hello.rb +➜ hello git:(master) ✗ git status +On branch master +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: hello.rb +``` +I've staged the changes made to `hello.rb`. The `git status` command now shows that the file is ready to be committed. +# Lab 7 +Explained about staging and committing changes in Git. Staging allows you to prepare changes before committing them to the repository. The `git add` command stages changes, while `git commit` saves those changes to the repository with a message describing the changes. +# Lab 8 +```bash +➜ hello git:(master) ✗ git commit +[master 0136159] Using ARGV + 1 file changed, 1 insertion(+), 1 deletion(-) +➜ hello git:(master) git status +On branch master +nothing to commit, working tree clean +``` +Ive got Nano as default editor, so I had to use `git commit` without the `-m` flag to write a commit message. The commit was successful, and the working tree is clean. +# Lab 9 +```bash +➜ hello git:(master) echo 'name = ARGV.first || "World"' > hello.rb +➜ hello git:(master) ✗ echo 'puts "Hello, #{name}!"' >> hello.rb + +➜ hello git:(master) ✗ cat hello.rb +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(master) ✗ git add hello.rb +➜ hello git:(master) ✗ vim hello.rb +➜ hello git:(master) ✗ cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(master) ✗ git status +On branch master +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: hello.rb + +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: hello.rb + +➜ hello git:(master) ✗ git commit -m "Added a default value" +[master 0a4623a] Added a default value + 1 file changed, 2 insertions(+), 1 deletion(-) +➜ hello git:(master) ✗ git status +On branch master +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: hello.rb + +no changes added to commit (use "git add" and/or "git commit -a") +➜ hello git:(master) ✗ git add . +➜ hello git:(master) ✗ git status +On branch master +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: hello.rb + +➜ hello git:(master) ✗ git commit -m "Added a comment" +[master 5f9df6a] Added a comment + 1 file changed, 1 insertion(+) +``` +Notice how `hello.rb` is listed twice in the status. The first change (adding a default) is staged and is ready to be committed. The second change (adding a comment) is unstaged. If you were to commit right now, the comment would not be saved in the repository. + +# Lab 10 +```bash +git log +git log --pretty=oneline +git log --pretty=oneline --max-count=2 +git log --pretty=oneline --since='5 minutes ago' +git log --pretty=oneline --until='5 minutes ago' +git log --pretty=oneline --author= +git log --pretty=oneline --all +git log --all --pretty=format:'%h %cd %s (%an)' --since='7 days ago' +git log --all --pretty=format:'%h %cd %s (%an)' --since='7 days ago' --author= +git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short +``` +The `--pretty="..."` option customizes how each commit is displayed in the log output. Here are some common placeholders used in the format string: + +- `%h`: Abbreviated commit hash +- `%d`: Decorations (e.g., branch names, tags) +- `%ad`: Author date (format can be customized with `--date=...`) +- `%s`: Commit message (subject) +- `%an`: Author name + +The `--graph` flag adds an ASCII graph showing the branch and merge history, making it easier to visualize the commit tree. Using `--date=short` displays dates in a concise `YYYY-MM-DD` format. + +# Lab 11 +Added first set of aliases to `~/.gitconfig`: +```ini +[alias] + co = checkout + ci = commit + st = status + br = branch + hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short + type = cat-file -t + dump = cat-file -p +``` +Second set of aliases to `.zshrc`: +```ini +alias gst='git status ' +alias ga='git add ' +alias gb='git branch ' +alias gc='git commit' +alias gd='git diff' +alias gco='git checkout ' +alias gk='gitk --all&' +alias gx='gitx --all' +``` + +# Lab 12 +```bash +➜ hello git:(main) git hist +➜ hello git:(main) gco 0a4623a +Note: switching to '0a4623a'. + +You are in 'detached HEAD' state. You can look around, make experimental +changes and commit them, and you can discard any commits you make in this +state without impacting any branches by switching back to a branch. + +If you want to create a new branch to retain commits you create, you may +do so (now or later) by using -c with the switch command. Example: + + git switch -c + +Or undo this operation with: + + git switch - + +Turn off this advice by setting config variable advice.detachedHead to false + +HEAD is now at 0a4623a Added a default value +➜ hello git:(0a4623a) cat hello.rb +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(0a4623a) gco main +Previous HEAD position was 0a4623a Added a default value +Switched to branch 'main' +➜ hello git:(main) cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +``` +I used the `git hist` alias to view the commit history, then checked out a specific commit using `gco 0a4623a`. After viewing the file at that commit, I switched back to the `main` branch using `gco main`. +# Lab 13 +```bash +➜ hello git:(main) git tag v1 +➜ hello git:(main) gco v1^ +Note: switching to 'v1^'. + +You are in 'detached HEAD' state. You can look around, make experimental +changes and commit them, and you can discard any commits you make in this +state without impacting any branches by switching back to a branch. + +If you want to create a new branch to retain commits you create, you may +do so (now or later) by using -c with the switch command. Example: + + git switch -c + +Or undo this operation with: + + git switch - + +Turn off this advice by setting config variable advice.detachedHead to false + +HEAD is now at 0a4623a Added a default value +➜ hello git:(0a4623a) cat hello.rb +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(0a4623a) git tag v1-beta +➜ hello git:(v1-beta) gco v1 +Previous HEAD position was 0a4623a Added a default value +HEAD is now at 5f9df6a Added a comment +➜ hello git:(v1) cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(v1) gco v1-beta +Previous HEAD position was 5f9df6a Added a comment +HEAD is now at 0a4623a Added a default value +➜ hello git:(v1-beta) cat hello.rb +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(v1-beta) git hist -a +➜ hello git:(v1-beta) gco v1 +Previous HEAD position was 0a4623a Added a default value +HEAD is now at 5f9df6a Added a comment +➜ hello git:(v1) git hist -a +``` +I created a tag `v1` at the commit `0a4623a`, then checked out the commit before the tag using `gco v1^`. I made a new tag `v1-beta` at that commit. After checking out the `v1` tag, I verified that the file content was as expected. Finally, I used `git hist -a` to view the commit history with all branches and tags. + +# Lab 14 +```bash +➜ hello git:(v1) gco main +Switched to branch 'main' +➜ hello git:(main) cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) vim hello.rb +➜ hello git:(main) ✗ gst +On branch main +Changes not staged for commit: + (use "git add ..." to update what will be committed) + (use "git restore ..." to discard changes in working directory) + modified: hello.rb + +no changes added to commit (use "git add" and/or "git commit -a") +➜ hello git:(main) ✗ gco hello.rb +Updated 1 path from the index +➜ hello git:(main) gst +On branch main +nothing to commit, working tree clean +➜ hello git:(main) cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +``` +I switched to the `main` branch, modified `hello.rb`, and then used `gco hello.rb` to restore the file to its last committed state. The `git status` command confirmed that there were no changes left in the working tree, and the file content was restored to its previous state. + +# Lab 15 +```bash +➜ hello git:(main) cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) vim hello.rb +➜ hello git:(main) ✗ ga hello.rb +➜ hello git:(main) ✗ gst +On branch main +Changes to be committed: + (use "git restore --staged ..." to unstage) + modified: hello.rb + +➜ hello git:(main) ✗ cat hello.rb +# This is an unwanted but staged comment +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) ✗ gco hello.rb +Updated 0 paths from the index +➜ hello git:(main) ✗ cat hello.rb +# This is an unwanted but staged comment +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) ✗ git reset HEAD hello.rb +Unstaged changes after reset: +M hello.rb +➜ hello git:(main) ✗ gco hello.rb +Updated 1 path from the index +➜ hello git:(main) gst +On branch main +nothing to commit, working tree clean +➜ hello git:(main) cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +``` +I staged a change in `hello.rb` that I didn't want to keep, then used `git reset HEAD hello.rb` to unstage it. After that, I restored the file to its last committed state using `gco hello.rb`, which reverted the unwanted change. The `git status` command confirmed that there were no changes left in the working tree, and the file content was restored to its previous state. + +# Lab 16 +```bash +➜ hello git:(main) vim hello.rb +➜ hello git:(main) ✗ cat hello.rb +# This is an unwanted but committed comment +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) ✗ ga hello.rb +➜ hello git:(main) ✗ gc -m "Oops, we didn't want this commit" +[main db8e267] Oops, we didn't want this commit + 1 file changed, 1 insertion(+), 1 deletion(-) +➜ hello git:(main) cat hello.rb +# This is an unwanted but committed comment +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) git revert HEAD +[main c4d7a0a] Revert "Oops, we didn't want this commit" + 1 file changed, 1 insertion(+), 1 deletion(-) +➜ hello git:(main) cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) git hist -a +``` +I made an unwanted commit to `hello.rb`, then used `git revert HEAD` to create a new commit that undoes the changes made in the last commit. The file content was restored to its previous state, and the `git hist -a` command confirmed the new revert commit in the history. + +# Lab 17 +```bash +➜ hello git:(main) git hist +➜ hello git:(main) git tag oops +➜ hello git:(main) git reset --hard v1 +HEAD is now at 5f9df6a Added a comment +➜ hello git:(main) git hist +➜ hello git:(main) cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +``` +I created a tag `oops` at the current commit, then used `git reset --hard v1` to reset the repository to the state of the `v1` tag. This command discarded all changes made after the `v1` tag, including the unwanted commit. The file content was restored to its state at the `v1` tag, and the `git hist` command confirmed that the history was reset accordingly. +Resets on local branches are generally safe. Any “accidents” can usually be recovered from by just resetting again with the desired commit. + +However, if the branch is shared on remote repositories, resetting can confuse other users sharing the branch. +# Lab 18 +```bash +hello git:(main) git tag -d oops +Deleted tag 'oops' (was c4d7a0a) +➜ hello git:(main) git hist -a +``` +The oops tag is no longer listed in the repository. + +# Lab 19 +```bash +➜ hello git:(main) cat hello.rb +# Default is "World" +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) vim hello.rb +➜ hello git:(main) ✗ cat hello.rb +# Default is "World" +# Author: D3LET3 +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) ✗ git add hello.rb +➜ hello git:(main) ✗ git commit -m "Add an author comment" +[main a69a526] Add an author comment + 1 file changed, 1 insertion(+) +➜ hello git:(main) cat hello.rb +# Default is "World" +# Author: D3LET3 +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) vim hello.rb +➜ hello git:(main) ✗ cat hello.rb +# Default is "World" +# Author: D3LET3 +# Email: REDACTED +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) ✗ git add hello.rb +➜ hello git:(main) ✗ git commit --amend -m "Add an author/email comment" +[main 85af29c] Add an author/email comment + Date: Tue Jun 3 16:29:38 2025 +0530 + 1 file changed, 2 insertions(+) +➜ hello git:(main) git hist -a +``` +I added an author comment to `hello.rb`, committed it, then amended the commit to include an email address. The `git hist -a` command confirmed the updated commit history with the new author and email comments. +# Lab 20 +```bash +➜ hello git:(main) mkdir lib +➜ hello git:(main) git mv hello.rb lib +➜ hello git:(main) ✗ git status +On branch main +Changes to be committed: + (use "git restore --staged ..." to unstage) + renamed: hello.rb -> lib/hello.rb + +➜ hello git:(main) ✗ git commit -m "Moved hello.rb to lib" +[main 20e3e36] Moved hello.rb to lib + 1 file changed, 0 insertions(+), 0 deletions(-) + rename hello.rb => lib/hello.rb (100%) +➜ hello git:(main) ls +lib +``` +I moved `hello.rb` to a new directory called `lib` using `git mv`, then committed the change. The `git status` command confirmed that the file was renamed and staged for commit, and the commit history was updated accordingly. +# Lab 21 +```bash +➜ hello git:(main) vim Rakefile +➜ hello git:(main) ✗ cat Rakefile +#!/usr/bin/ruby -wKU + +task :default => :run + +task :run do + require './lib/hello' +end + +➜ hello git:(main) ✗ git add Rakefile +➜ hello git:(main) ✗ gc -m "Added a Rakefile" +[main 4dbc382] Added a Rakefile + 1 file changed, 8 insertions(+) + create mode 100644 Rakefile +➜ hello git:(main) rake +Hello, World! +``` +I created a `Rakefile` that defines a default task to run the `hello.rb` script located in the `lib` directory. After adding and committing the `Rakefile`, I ran `rake`, which executed the task and printed "Hello, World!" to the console. +# Lab 22 +```bash +➜ hello git:(main) ls -C .git +branches COMMIT_EDITMSG config description HEAD hooks index info logs objects ORIG_HEAD packed-refs refs +➜ hello git:(main) ls -C .git/objects +01 0a 11 16 20 27 29 40 47 4d 50 59 5a 5f 6f 71 7c 84 85 8c a6 af c4 c5 db ed f2 info pack +➜ hello git:(main) ls -C .git/objects/01 +3615927a2efd63ddea466b0952e481c6f73bc4 +➜ hello git:(main) cat .git/config +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true +➜ hello git:(main) ls .git/refs +heads tags +➜ hello git:(main) ls .git/refs/heads +main +➜ hello git:(main) ls .git/refs/tags +v1 v1-beta +➜ hello git:(main) ls .git/refs/tags/v1 +.git/refs/tags/v1 +➜ hello git:(main) cat .git/refs/tags/v1 +5f9df6a02d6ccc4ad98703cf84ea0e47b5aec2ff +➜ hello git:(main) cat .git/HEAD +ref: refs/heads/main +``` +I explored the `.git` directory structure, which contains various files and directories that Git uses to manage the repository. Key components include: +- `.git/objects`: Stores all the objects (blobs, trees, commits) that make up the repository. +- `.git/refs`: Contains references to commits, including branches and tags. +- `.git/config`: The configuration file for the repository, which includes settings like file mode and bare repository status. +- `.git/HEAD`: Points to the current branch or commit, indicating the state of the working directory. +# Lab 23 +```bash +➜ hello git:(main) git hist --max-count=1 +➜ hello git:(main) git cat-file -t 4dbc382 +commit +➜ hello git:(main) git cat-file -p 4dbc382 +tree 5a96ab208ab1b85cc72fcfd0ec7e7331be37a12e +parent 20e3e36cf348faa3f398431ad4da63d397407098 +author D3LET3-57 1748949031 +0530 +committer D3LET3-57 1748949031 +0530 + +Added a Rakefile +➜ hello git:(main) git cat-file -p 5a96ab208ab1b85cc72fcfd0ec7e7331be37a12e +100644 blob f21f041d8674f589298d160e0a1b55e01a3d4247 Rakefile +040000 tree 6f7e18702e74ce163490b473b4f4441d852c4791 lib +➜ hello git:(main) git cat-file -p 6f7e18702e74ce163490b473b4f4441d852c4791 +100644 blob 50fe9e8e7452eab5f47145f9e0f54d74f803e423 hello.rb +➜ hello git:(main) git cat-file -p 50fe9e8e7452eab5f47145f9e0f54d74f803e423 +# Default is "World" +# Author: D3LET3 +# Email: REDACTED +name = ARGV.first || "World" +puts "Hello, #{name}!" +``` +I used `git cat-file` to inspect the commit object `4dbc382`, which shows the tree structure and parent commit. The tree object `5a96ab208ab1b85cc72fcfd0ec7e7331be37a12e` contains the files in the commit, including the `Rakefile` and the `hello.rb` file in the `lib` directory. The content of `hello.rb` is displayed, confirming the changes made in the commit. +# Lab 24 +```bash +➜ hello git:(main) gco -b greet +Switched to a new branch 'greet' +➜ hello git:(greet) +➜ hello git:(greet) git status +On branch greet +nothing to commit, working tree clean +➜ hello git:(greet) ls +lib Rakefile +➜ hello git:(greet) vim lib/greeter.rb +➜ hello git:(greet) ✗ ga lib/greeter.rb +➜ hello git:(greet) ✗ gc -m "Added a greeter class" +[greet 047fc2b] Added a greeter class + 1 file changed, 8 insertions(+) + create mode 100644 lib/greeter.rb +➜ hello git:(greet) vim lib/hello.rb +➜ hello git:(greet) ✗ ga lib/hello.rb +➜ hello git:(greet) ✗ gc -m "Hello uses Greeter" + +[greet e64c2f8] Hello uses Greeter + 1 file changed, 6 insertions(+), 4 deletions(-) +➜ hello git:(greet) ✗ +➜ hello git:(greet) vim Rakefile +➜ hello git:(greet) ✗ ga Rakefile +➜ hello git:(greet) ✗ gc -m "Updated Rakefile" +[greet cb4831a] Updated Rakefile + 1 file changed, 1 insertion(+), 2 deletions(-) + ``` + I created a new branch `greet`, added a `greeter.rb` class, modified `hello.rb` to use the `Greeter` class, and updated the `Rakefile` accordingly. Each change was staged and committed with appropriate messages. The `git status` command confirmed that there were no changes left to commit in the working tree. + +# Lab 25 +```bash +➜ hello git:(greet) gco main +Switched to branch 'main' +➜ hello git:(main) cat lib/hello.rb +# Default is "World" +# Author: D3LET3 +# Email: REDACTED +name = ARGV.first || "World" +puts "Hello, #{name}!" +➜ hello git:(main) gco greet +Switched to branch 'greet' +➜ hello git:(greet) cat lib/hello.rb +require 'greeter' + +# Default is World +name = ARGV.first || "World" + +greeter = Greeter.new(name) +puts greeter.greet +``` +I switched back to the `main` branch to view the original `hello.rb` file, then switched to the `greet` branch to see the modified version that uses the `Greeter` class. The content of `hello.rb` in the `greet` branch reflects the changes made in that branch. +# Lab 26 +```bash +➜ hello git:(greet) gco main +Switched to branch 'main' +➜ hello git:(main) vim README.md +➜ hello git:(main) ✗ cat README.md +This is the Hello World example from the git tutorial. + +➜ hello git:(main) ✗ git add README +fatal: pathspec 'README' did not match any files +➜ hello git:(main) ✗ git add README.md +➜ hello git:(main) ✗ git commit -m "Added README" +[main 895a1b8] Added README + 1 file changed, 2 insertions(+) + create mode 100644 README.md +``` +I added a `README.md` file to the `main` branch with a brief description of the project. The file was staged and committed successfully, and the commit history was updated accordingly. +# Lab 27 +```bash + hello git:(main) git hist -a +* 895a1b8 2025-06-03 | Added README (HEAD -> main) [D3LET3-57] +* 4dbc382 2025-06-03 | Added a Rakefile [D3LET3-57] +* 20e3e36 2025-06-03 | Moved hello.rb to lib [D3LET3-57] +* 85af29c 2025-06-03 | Add an author/email comment [D3LET3-57] +* 5f9df6a 2025-06-03 | Added a comment (tag: v1) [D3LET3-57] +* 0a4623a 2025-06-03 | Added a default value (tag: v1-beta) [D3LET3-57] +* 0136159 2025-06-03 | Using ARGV [D3LET3-57] +* 8c91514 2025-06-03 | First Commit [D3LET3-57] +``` +I used `git hist -a` to view the commit history, which now includes the new `README.md` file and all previous commits. The output shows the commit hashes, dates, messages, and authors for each commit, providing a complete overview of the project's history. +# Lab 28 +```bash + hello git:(main) gco greet +Switched to branch 'greet' +➜ hello git:(greet) type gm +gm is an alias for git merge +➜ hello git:(greet) gm main +Merge made by the 'ort' strategy. + README.md | 2 ++ + 1 file changed, 2 insertions(+) + create mode 100644 README.md +* 58c0382 2025-06-03 | Merge branch 'main' into greet (HEAD -> greet) [D3LET3-57] +|\ +| * 895a1b8 2025-06-03 | Added README (main) [D3LET3-57] +* | cb4831a 2025-06-03 | Updated Rakefile [D3LET3-57] +* | e64c2f8 2025-06-03 | Hello uses Greeter [D3LET3-57] +* | 047fc2b 2025-06-03 | Added a greeter class [D3LET3-57] +|/ +* 4dbc382 2025-06-03 | Added a Rakefile [D3LET3-57] +* 20e3e36 2025-06-03 | Moved hello.rb to lib [D3LET3-57] +* 85af29c 2025-06-03 | Add an author/email comment [D3LET3-57] +* 5f9df6a 2025-06-03 | Added a comment (tag: v1) [D3LET3-57] +* 0a4623a 2025-06-03 | Added a default value (tag: v1-beta) [D3LET3-57] +* 0136159 2025-06-03 | Using ARGV [D3LET3-57] +* 8c91514 2025-06-03 | First Commit [D3LET3-57] +``` +I merged the `main` branch into the `greet` branch using the `gm` alias for `git merge`. The merge was successful, and the `README.md` file was added to the `greet` branch. The commit history now reflects the merge, showing the combined changes from both branches. + +# Lab 29 +```bash +➜ hello git:(greet) gco main +Switched to branch 'main' +➜ hello git:(main) vim lib/hello.rb +➜ hello git:(main) ✗ git add lib/hello.rb +➜ hello git:(main) ✗ git commit -m "Made interactive" +[main 1277033] Made interactive + 1 file changed, 4 insertions(+), 5 deletions(-) +➜ hello git:(main) git hist --all +* 1277033 2025-06-03 | Made interactive (HEAD -> main) [D3LET3-57] +| * 58c0382 2025-06-03 | Merge branch 'main' into greet (greet) [D3LET3-57] +| |\ +| |/ +|/| +* | 895a1b8 2025-06-03 | Added README [D3LET3-57] +| * cb4831a 2025-06-03 | Updated Rakefile [D3LET3-57] +| * e64c2f8 2025-06-03 | Hello uses Greeter [D3LET3-57] +| * 047fc2b 2025-06-03 | Added a greeter class [D3LET3-57] +|/ +* 4dbc382 2025-06-03 | Added a Rakefile [D3LET3-57] +* 20e3e36 2025-06-03 | Moved hello.rb to lib [D3LET3-57] +* 85af29c 2025-06-03 | Add an author/email comment [D3LET3-57] +* 5f9df6a 2025-06-03 | Added a comment (tag: v1) [D3LET3-57] +* 0a4623a 2025-06-03 | Added a default value (tag: v1-beta) [D3LET3-57] +* 0136159 2025-06-03 | Using ARGV [D3LET3-57] +* 8c91514 2025-06-03 | First Commit [D3LET3-57] +``` +I modified `lib/hello.rb` to make it interactive, allowing the user to input their name. After staging and committing the changes, I used `git hist --all` to view the complete commit history across all branches. The output shows the latest commit on the `main` branch and the merge commit from the `greet` branch, along with all previous commits. +# Lab 30 +```bash +➜ hello git:(main) gco greet +Switched to branch 'greet' +➜ hello git:(greet) gm main +Auto-merging lib/hello.rb +CONFLICT (content): Merge conflict in lib/hello.rb +Automatic merge failed; fix conflicts and then commit the result. +➜ hello git:(greet) ✗ cat lib/hello.rb +<<<<<<< HEAD +require 'greeter' + +# Default is World +name = ARGV.first || "World" + +greeter = Greeter.new(name) +puts greeter.greet +======= +puts "What's your name" +my_name = gets.strip + +puts "Hello, #{my_name}!" +>>>>>>> main +➜ hello git:(greet) ✗ vim lib/hello.rb +➜ hello git:(greet) ✗ git add lib/hello.rb +➜ hello git:(greet) ✗ git commit -m "Merged main fixed conflict." +[greet 7913c56] Merged main fixed conflict. +➜ hello git:(greet) +``` +I attempted to merge the `main` branch into the `greet` branch, which resulted in a merge conflict in `lib/hello.rb`. I resolved the conflict by editing the file to combine both changes, then staged and committed the resolved file. The commit history was updated to reflect the merge resolution. +# Lab 31 +Let’s explore the differences between merging and rebasing. In order to do so, we need to rewind the repository back in time before the first merge, and then redo the same steps, but using rebasing rather than merging. + +We will make use the of the reset command to wind the branches back in time. + +# Lab 32 +```bash +➜ hello git:(greet) gco greet +Already on 'greet' +➜ hello git:(greet) git hist +* 7913c56 2025-06-03 | Merged main fixed conflict. (HEAD -> greet) [D3LET3-57] +|\ +| * 1277033 2025-06-03 | Made interactive (main) [D3LET3-57] +* | 58c0382 2025-06-03 | Merge branch 'main' into greet [D3LET3-57] +|\| +| * 895a1b8 2025-06-03 | Added README [D3LET3-57] +* | cb4831a 2025-06-03 | Updated Rakefile [D3LET3-57] +* | e64c2f8 2025-06-03 | Hello uses Greeter [D3LET3-57] +* | 047fc2b 2025-06-03 | Added a greeter class [D3LET3-57] +|/ +* 4dbc382 2025-06-03 | Added a Rakefile [D3LET3-57] +* 20e3e36 2025-06-03 | Moved hello.rb to lib [D3LET3-57] +* 85af29c 2025-06-03 | Add an author/email comment [D3LET3-57] +* 5f9df6a 2025-06-03 | Added a comment (tag: v1) [D3LET3-57] +* 0a4623a 2025-06-03 | Added a default value (tag: v1-beta) [D3LET3-57] +* 0136159 2025-06-03 | Using ARGV [D3LET3-57] +* 8c91514 2025-06-03 | First Commit [D3LET3-57] +#That’s a bit hard to read, but looking at the data we see that the “Updated Rakefile” commit was the last commit on the greet branch before merging. Let’s reset the greet branch to that commit. +➜ hello git:(greet) git reset --hard cb4831a +HEAD is now at cb4831a Updated Rakefile +➜ hello git:(greet) git hist --all +* 1277033 2025-06-03 | Made interactive (main) [D3LET3-57] +* 895a1b8 2025-06-03 | Added README [D3LET3-57] +| * cb4831a 2025-06-03 | Updated Rakefile (HEAD -> greet) [D3LET3-57] +| * e64c2f8 2025-06-03 | Hello uses Greeter [D3LET3-57] +| * 047fc2b 2025-06-03 | Added a greeter class [D3LET3-57] +|/ +* 4dbc382 2025-06-03 | Added a Rakefile [D3LET3-57] +* 20e3e36 2025-06-03 | Moved hello.rb to lib [D3LET3-57] +* 85af29c 2025-06-03 | Add an author/email comment [D3LET3-57] +* 5f9df6a 2025-06-03 | Added a comment (tag: v1) [D3LET3-57] +* 0a4623a 2025-06-03 | Added a default value (tag: v1-beta) [D3LET3-57] +* 0136159 2025-06-03 | Using ARGV [D3LET3-57] +* 8c91514 2025-06-03 | First Commit [D3LET3-57] +``` +The `greet` branch has been reset to the commit before the merge, which is `cb4831a`. The commit history now shows that the `greet` branch is at the same point as it was before the merge, with no merge commits present. +# Lab 33 +```bash +➜ hello git:(main) git reset --hard 895a1b8 +HEAD is now at 895a1b8 Added README +➜ hello git:(main) git hist --all +* 895a1b8 2025-06-03 | Added README (HEAD -> main) [D3LET3-57] +| * cb4831a 2025-06-03 | Updated Rakefile (greet) [D3LET3-57] +| * e64c2f8 2025-06-03 | Hello uses Greeter [D3LET3-57] +| * 047fc2b 2025-06-03 | Added a greeter class [D3LET3-57] +|/ +* 4dbc382 2025-06-03 | Added a Rakefile [D3LET3-57] +* 20e3e36 2025-06-03 | Moved hello.rb to lib [D3LET3-57] +* 85af29c 2025-06-03 | Add an author/email comment [D3LET3-57] +* 5f9df6a 2025-06-03 | Added a comment (tag: v1) [D3LET3-57] +* 0a4623a 2025-06-03 | Added a default value (tag: v1-beta) [D3LET3-57] +* 0136159 2025-06-03 | Using ARGV [D3LET3-57] +* 8c91514 2025-06-03 | First Commit [D3LET3-57] +``` +The ‘Added README’ commit is the one directly before the conflicting interactive mode. We will reset the main branch to ‘Added README’ commit. +# Lab 34 +```bash +➜ hello git:(main) gco greet +Switched to branch 'greet' +➜ hello git:(greet) git rebase main +Successfully rebased and updated refs/heads/greet. +➜ hello git:(greet) git hist +* 07fb1d7 2025-06-03 | Updated Rakefile (HEAD -> greet) [D3LET3-57] +* 8540dcb 2025-06-03 | Hello uses Greeter [D3LET3-57] +* 9dc4ab9 2025-06-03 | Added a greeter class [D3LET3-57] +* 895a1b8 2025-06-03 | Added README (main) [D3LET3-57] +* 4dbc382 2025-06-03 | Added a Rakefile [D3LET3-57] +* 20e3e36 2025-06-03 | Moved hello.rb to lib [D3LET3-57] +* 85af29c 2025-06-03 | Add an author/email comment [D3LET3-57] +* 5f9df6a 2025-06-03 | Added a comment (tag: v1) [D3LET3-57] +* 0a4623a 2025-06-03 | Added a default value (tag: v1-beta) [D3LET3-57] +* 0136159 2025-06-03 | Using ARGV [D3LET3-57] +* 8c91514 2025-06-03 | First Commit [D3LET3-57] +``` +Merge v/s Rebase
+The `greet` branch has been successfully rebased onto the `main` branch. The commit history now shows that the commits from the `greet` branch have been applied on top of the `main` branch, creating a linear history without any merge commits. This makes the history cleaner and easier to follow. +# Lab 35 +```bash +➜ hello git:(greet) gco main +Switched to branch 'main' +➜ hello git:(main) gm greet +Updating 895a1b8..07fb1d7 +Fast-forward + Rakefile | 3 +-- + lib/greeter.rb | 8 ++++++++ + lib/hello.rb | 10 ++++++---- + 3 files changed, 15 insertions(+), 6 deletions(-) + create mode 100644 lib/greeter.rb +➜ hello git:(main) git hist +* 07fb1d7 2025-06-03 | Updated Rakefile (HEAD -> main, greet) [D3LET3-57] +* 8540dcb 2025-06-03 | Hello uses Greeter [D3LET3-57] +* 9dc4ab9 2025-06-03 | Added a greeter class [D3LET3-57] +* 895a1b8 2025-06-03 | Added README [D3LET3-57] +* 4dbc382 2025-06-03 | Added a Rakefile [D3LET3-57] +* 20e3e36 2025-06-03 | Moved hello.rb to lib [D3LET3-57] +* 85af29c 2025-06-03 | Add an author/email comment [D3LET3-57] +* 5f9df6a 2025-06-03 | Added a comment (tag: v1) [D3LET3-57] +* 0a4623a 2025-06-03 | Added a default value (tag: v1-beta) [D3LET3-57] +* 0136159 2025-06-03 | Using ARGV [D3LET3-57] +* 8c91514 2025-06-03 | First Commit [D3LET3-57] +``` +Because the head of main is a direct ancestor of the head of the greet branch, git is able to do a fast-forward merge. When fast-forwarding, the branch pointer is simply moved forward to point to the same commit as the greeter branch. + +There will never be conflicts in a fast-forward merge. +Unlike a merge, rebasing does not create a new commit. Instead, it rewrites the commit history by applying the changes from one branch onto another. This results in a cleaner, linear history without merge commits, making it easier to understand the project’s evolution. diff --git a/Lalith/Assignment_2/hello b/Lalith/Assignment_2/hello new file mode 160000 index 0000000..07fb1d7 --- /dev/null +++ b/Lalith/Assignment_2/hello @@ -0,0 +1 @@ +Subproject commit 07fb1d7af6f3c331b7b133ddaef8d4c7d6fcaea3 From 6a04588574ba6abf9caca095b9cdd623fddb9ab8 Mon Sep 17 00:00:00 2001 From: D3LET3-57 Date: Tue, 3 Jun 2025 20:28:08 +0530 Subject: [PATCH 3/7] PC guardina script --- Lalith/Assignment_3/script.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Lalith/Assignment_3/script.sh diff --git a/Lalith/Assignment_3/script.sh b/Lalith/Assignment_3/script.sh new file mode 100644 index 0000000..e69de29 From 7d3dd33e2e6436484149012fbc6d199d517fb58c Mon Sep 17 00:00:00 2001 From: D3LET3-57 Date: Tue, 3 Jun 2025 20:37:56 +0530 Subject: [PATCH 4/7] Add Readme file for PC Guardian --- Lalith/Assignment_3/README.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Lalith/Assignment_3/README.md diff --git a/Lalith/Assignment_3/README.md b/Lalith/Assignment_3/README.md new file mode 100644 index 0000000..55acb1b --- /dev/null +++ b/Lalith/Assignment_3/README.md @@ -0,0 +1,19 @@ +# PC Guardian +## `libinput` +This tool help us to record the input devices from our system.
+- `libinput list-devices` - List all input devices. +- `libinput debug-events` - Monitor input events in real-time. + - We are using this command to record the input events from the system. + - It reads from the `/dev/input/event*` files. +## `espeak` +We use this tool to convert text to speech.
+- `espeak -s 150 -p 50 -v en-us "Hello World"` - Convert text to speech. + - `-s` is the speed of the speech. + - `-p` is the pitch of the speech. + - `-v` is the voice of the speech. +# What it does? +- Logs detection of input devices. +- Triggeres an alert when a mouse movement is detected. +- Converts the alert message to speech. +- Has 10s sleep time to avoid multiple alerts. +- Threshold time for mouse movement is 1ms. From 504f47e938ec1f75b41fc40e00d90b739e76f2ba Mon Sep 17 00:00:00 2001 From: D3LET3-57 Date: Tue, 3 Jun 2025 20:56:35 +0530 Subject: [PATCH 5/7] Solutions for The Shell --- Lalith/missing_semester/The_shell/README.md | 69 +++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Lalith/missing_semester/The_shell/README.md diff --git a/Lalith/missing_semester/The_shell/README.md b/Lalith/missing_semester/The_shell/README.md new file mode 100644 index 0000000..366d209 --- /dev/null +++ b/Lalith/missing_semester/The_shell/README.md @@ -0,0 +1,69 @@ +# Missing Semester - The shell +```bash +➜ DSG echo $SHELL + +/usr/bin/zsh +➜ DSG cd /tmp +➜ /tmp mkdir missing +➜ missing touch semester +➜ missing ls +semester +➜ missing vim semester +➜ missing cat semester +#!/bin/sh +curl --head --silent https://missing.csail.mit.edu +➜ missing ./semester +zsh: permission denied: ./semester +missing sh semester +HTTP/2 200 +server: GitHub.com +content-type: text/html; charset=utf-8 +last-modified: Sat, 19 Apr 2025 16:35:21 GMT +access-control-allow-origin: * +etag: "6803d0c9-205d" +expires: Tue, 03 Jun 2025 04:25:22 GMT +cache-control: max-age=600 +x-proxy-cache: MISS +x-github-request-id: A4B1:39F17E:C9837:F54D2:683E76DA +accept-ranges: bytes +age: 0 +date: Tue, 03 Jun 2025 15:22:58 GMT +via: 1.1 varnish +x-served-by: cache-maa10230-MAA +x-cache: HIT +x-cache-hits: 0 +x-timer: S1748964179.556839,VS0,VE232 +vary: Accept-Encoding +x-fastly-request-id: ad1e5ee275bec43d41de59c62121120265cea725 +content-length: 8285 +➜ missing chmod +x semester +➜ missing ./semester +HTTP/2 200 +server: GitHub.com +content-type: text/html; charset=utf-8 +last-modified: Sat, 19 Apr 2025 16:35:21 GMT +access-control-allow-origin: * +etag: "6803d0c9-205d" +expires: Tue, 03 Jun 2025 04:25:22 GMT +cache-control: max-age=600 +x-proxy-cache: MISS +x-github-request-id: A4B1:39F17E:C9837:F54D2:683E76DA +accept-ranges: bytes +date: Tue, 03 Jun 2025 15:23:27 GMT +via: 1.1 varnish +age: 29 +x-served-by: cache-maa10235-MAA +x-cache: HIT +x-cache-hits: 1 +x-timer: S1748964207.403865,VS0,VE1 +vary: Accept-Encoding +x-fastly-request-id: 351857597ed0a04d993ea9cb7f8310c767f9ab36 +content-length: 8285 +missing date -r semester > last_modified.txt +➜ missing cat last_modified.txt +Tue Jun 3 08:50:46 PM IST 2025 +missing cat /sys/class/power_supply/BAT0/capacity +65 +missing cat /sys/class/thermal/thermal_zone0/temp +43000 +``` \ No newline at end of file From a5dbe2e416c68c83870a196770aab105bcc71896 Mon Sep 17 00:00:00 2001 From: D3LET3-57 Date: Tue, 3 Jun 2025 21:21:37 +0530 Subject: [PATCH 6/7] Solutions for Shell Scripting --- .../Shell_Tools_and_Scripting/README.md | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Lalith/missing_semester/Shell_Tools_and_Scripting/README.md diff --git a/Lalith/missing_semester/Shell_Tools_and_Scripting/README.md b/Lalith/missing_semester/Shell_Tools_and_Scripting/README.md new file mode 100644 index 0000000..41ca9d4 --- /dev/null +++ b/Lalith/missing_semester/Shell_Tools_and_Scripting/README.md @@ -0,0 +1,39 @@ +# Shell Tools and Scripts +```bash + missing ls -la -h -t -r +total 32K +-rwxrwxr-x 1 delete delete 61 Jun 3 20:50 semester +drwxrwxr-x 2 delete delete 4.0K Jun 3 20:54 . +-rw-rw-r-- 1 delete delete 32 Jun 3 20:54 last_modified.txt +drwxrwxrwt 71 root root 20K Jun 3 21:01 .. +``` +`-l` - long listing format
+`-a` - include hidden files
+`-h` - human-readable sizes
+`-t` - sort by modification time, newest first
+`-r` - reverse order while sorting
+# This script defines two functions: marco and polo. +```bash +#!/bin/sh +marco(){ + export MARCO="$PWD" + # This function sets the MARCO variable to the current working directory. +} +polo(){ + if [ -z "$MARCO" ]; then + echo "MARCO is not set. Please run 'marco' first." + # -z checks if the variable is empty. + else + cd "$MARCO" || echo "Failed to change directory to $MARCO" + + fi +} +``` +## Usage +```console +➜ Downloads marco +➜ Downloads cd .. +➜ ~ polo +➜ Downloads +``` + From 9ea15c2934cf78797ab50ce2eba172edc2502fba Mon Sep 17 00:00:00 2001 From: D3LET3-57 Date: Tue, 3 Jun 2025 21:26:24 +0530 Subject: [PATCH 7/7] PC Guardian Script --- Lalith/Assignment_3/script.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Lalith/Assignment_3/script.sh b/Lalith/Assignment_3/script.sh index e69de29..2101fca 100644 --- a/Lalith/Assignment_3/script.sh +++ b/Lalith/Assignment_3/script.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +DEVICE="/dev/input/event5" +SOUND="Intruder detected! Step away from my PC!" +INACTIVITY_TIMEOUT=100 + +last_activity=$(date +%s) + +sudo libinput debug-events --device "$DEVICE" | while read -r line; do + now=$(date +%s) + + # Check if last activity was less than timeout ago + if (( now - last_activity >= INACTIVITY_TIMEOUT )); then + echo "[!] Motion detected at $(date)" + espeak "$SOUND" + last_activity=$now + sleep 10 # Avoid spamming sound + else + last_activity=$now + fi +done