----BEGIN CLASS---- [10:30] #startclass [10:30] Roll Call [10:30] Pallav Bhalla [10:30] vibhor [10:30] Nilesh Patra [10:30] Ritik Raushan [10:30] Philemon Johnson [10:30] Rayan Das [10:31] who all does not know git here [10:31] Md Salman Ansari [10:31] ? [10:31] me [10:31] me [10:31] Kuntal Majumder [10:31] *not me [10:31] me [10:31] me [10:31] me [10:31] sorry read it wrong [10:32] pallavbhalla: you know git? [10:32] mostly the basics [10:32] yes [10:32] basics [10:32] \o/ [10:32] Okay, I will be teaching basics today, so feel free to follow the class [10:34] who all are hearing about any version control system for the first time? [10:35] me [10:35] git, svn, mercurial are different version control system [10:35] I only know of git as version control [10:35] there are plenty more [10:35] Okay [10:36] knew about others but worked only on git [10:36] so, let us start with the definition of a version control system [10:36] a version control system, also known as VCS are a category of software that help manage the changes done in the code [10:37] suppose there are multiple people working on the same code-base, it becomes difficult syncing the changes [10:38] tell me, what if you need to collaborate with other teammates and get the code they are working on [10:38] how would you do that? [10:38] ! [10:39] given that you don't have prior knowledge of any vcs [10:39] next [10:39] ive used google drive in the past, along with pendrives [10:39] as a means to share code [10:40] exactly, you would be using other means to share code, but the problem here is you need to send the complete directory to that friend of yours [10:40] and then the other person manually checks and applies the changes you made [10:40] thus you need a software [10:40] One fine day, you plan to start a project of yours. [10:41] But maintaining and building a project is nevertheless a daunting task [10:41] You dream that your project would be a big & successful project. [10:41] A community of people are be using your project. [10:41] But, you are just a developer and at the end of the day a human. [10:41] You are ought to make mistakes, forget corner cases, make bunch of typos. [10:42] and all the other issues that you never even thought of. [10:42] But, that's when the community comes to rescue. They start filing up issues. [10:42] You solve them one by one. But. slowly, slowly, slowly. [10:42] Your issues counter has reached 1000. [10:43] Would you be celebrating this milestone? If I were you. I would be tensed. [10:43] There so much work years to spend just to fix those pending issues. [10:43] You wished you had a helping hand and the community who were just filing the issues [10:44] came to the forefront and started asking you on how can they help [10:44] with so much tension around, you did a big mistake, and deleted a big chunk of your code [10:45] *clicketty* *click* and gone [10:46] *and suddenly you wake and realize you were dreaming* [10:46] the project's fine but the issues counter is at 42. [10:46] you plan to take some action before things go out of hand [10:47] Sweating profusely, You thank your god for the blessing in disguise [10:47] You take an oath for each of your project you will be using a Version Control System a.k.a VCS [10:47] * end of prologue * [10:47] * Chapter 1: Understanding VCS: Commits * [10:48] Next day morning you start reading VCS, scratching your head to get around with all the terms [10:48] The first one that you hit is commits, so what is commit (or snapshot?) [10:48] So you thought of writing a series analogy stories to learn the concepts better, and blog it for future references :) [10:48] You create a new character, Tux [10:49] Tux wants to be photographer, who has just bought a new DSLR. [10:49] Tux plans to be the next famous travel photographer, who would take the best picture from the top of Mt. Everest [10:49] But Tux is a newbie, so Tux starts watching for YouTube tutorials for learning to post process the images. [10:50] Tux creates a directory named *working* to put all un-processed images. <<-- mind *working* is to be focused here [10:50] Then, fires up Photoshop to process the images. [10:51] Every time after a set of similar operations (like crop, rotate, increase brightness, decrease contrast etc), Tux creates a copy of the *working* directory and names it `snapshot-{n}` [10:51] so after cropping the image, Tux working directory and names it `snapshot-1` [10:52] Then Tux rotate, tilts the images to fix the horizon. Tux then copies the working directory and names it `snapshot-2` [10:52] After a couple of operations, Tux stands having "snapshot-1", "snapshot-2", "snapshot-3", .... , "snapshot-100" directories. [10:52] This directories is history of how Tux developed the image over time. At any point, Tux can go back to a given snapshot and build again on top of it. [10:53] * end of Chapter 1 * [10:53] any issues till following up here? [10:53] no [10:53] no [10:53] no [10:53] no [10:54] no [10:54] no [10:54] Moving ahead then [10:55] * Chapter 2: Understanding VCS: Staging Area * [10:55] It's been a month now, Tux have learned a lot on post-processing images. [10:56] Tux now mixes and matches multiple image files to create a snapshot directory. [10:56] One day, Tux while processing the images, goes into experimental mode. [10:56] and only after a while realized that the changes should be going into two different snapshot directories (`snapshot-139` & `snapshot-140`). [10:57] so Tux did a fix of the brightness of image_211.jpg and fix contrast in the file image_212.jpg [10:58] But both were in the working directory, so if he had copied the working directory it would have created only one snapshot directory [10:58] instead Tux wanted divide the work into two snapshots. [10:59] Smart Tux quickly thought of an idea, creates a new intermediate directory called *staging*. [10:59] A staging directory works as an intermediate between the working directory and the snapshot directory. [11:00] So, Tux now works on working directory, and one Tux is happy with the changes, Tux moves all changed files into staging directory. [11:00] and then creates a copy of the staging directory as new snapshot directory. [11:00] * end of chapter 2 * [11:00] any questions till here? [11:01] ! [11:01] next [11:01] can you elaborate "But both were in the working directory, so if he had copied the working directory it would have created only one snapshot directory" [11:02] so the working directory have suppose three files. a, b, c [11:02] Tux update a, and b. [11:02] Now from chapter 1 we know that we copy the working directory to create the snapshot directory [11:03] And the current point with updated a, and b, if Tux copies the working directory that would create only one new snapshot directory which would have both the changes [11:04] Rather Tux wants two have both changes in two different snapshots, so thus we need to staging directory [11:04] understood [11:05] fire up your terminals [11:05] (I mean that open up your terminals) [11:06] (I am not responsible if someone literally put their terminal on fire) [11:06] tell me when done [11:06] done [11:06] done [11:06] done [11:06] $ mkdir foobar [11:06] done [11:06] $ cd foobar [11:07] $ vim helloworld.txt # write "Snapshot 1" inside the file [11:07] dono [11:07] done* [11:07] done [11:08] who all are still doing? [11:08] done [11:08] done [11:08] done [11:08] done [11:08] done [11:08] done [11:09] the first thing that we do is configure our git [11:09] this is to be done only once [11:09] when you setting up git in your brand new shiny machine [11:10] we set up our name and email [11:10] $ git config --global user.name "" [11:10] $ git config --global user.email "" [11:10] tell me when done [11:10] git config [11:11] sorry [11:11] already configured [11:11] okay [11:12] already configured [11:13] should I move ahead? [11:14] yes [11:14] yes [11:14] $ git init # do this in the foobar directory [11:14] yes [11:15] Initialized empty Git repository in /home/hackman/foobar/.git/ [11:15] raydeeam: yes [11:15] yes [11:15] now git in not tracking any files in the foobar directory [11:15] you need to explicitly tell git to track new files you add in the directory [11:15] you do that using: [11:15] $ git add helloworld.txt [11:17] now if you do: [11:17] $ git status [11:17] No commits yet [11:17] you would see "Changes to be committed" and beneath it written the name of the file [11:17] iinternaut: ? [11:17] yes [11:18] yes [11:18] This area "Changes to be committed" is known as the staging area [11:18] Relate to the analogy we studies in the Tux story [11:19] This is the place we review our commits one file time before creating the commit (from ananlogy story, the snapshot directory) [11:19] to create the commit, you do: [11:19] - git commit -m "Snapshot 1" [11:19] $ git commit -m "Snapshot 1" [11:19] tell me when done [11:20] done [11:20] done [11:20] done [11:22] here we are using `-m` when using the commit sub-command [11:22] this argument is used to specify the message [11:22] moving ahead [11:22] $ vim helloworld.txt # Add "Snapshot 2" to the file [11:22] $ git status [11:23] What do you see? Can some one write what does `git status` show? [11:23] Changes not staged for commit: [11:23] modified: helloworld.txt [11:24] right, so this is the working directory, none of our changes right now are in the staging area [11:24] so if we try to do $ git commit [11:25] it would throw us an error [11:25] When working on a big project, we continue to work on files, and the diff are accumulated here, and seen here [11:26] until you move those changes from working directory to staging, they will not be committed [11:26] and it's possible to loose those changes if something happens [11:26] so it is told commit early, commit often [11:26] understood? [11:26] yes [11:27] Yes [11:27] yes [11:27] yes [11:27] moving ahead [11:28] so how to check the changes you have done since the last time you did a commit? [11:28] The command is [11:28] $ git diff [11:28] what do you see? [11:29] the file name with a +green line showing the new change [11:29] +Snapshot 2 [11:30] right + Snapshot 2, BhaveshSGupta diff looks different as the line was replaced with Snapshot 2 in this case [11:30] so here you would see bunch of `+` and `-` [11:30] If the lines are added then `+`, else `-` [11:30] by else I mean remove :) [11:31] now tell me how to move this change to staging area for the commit to be committed? [11:31] ! [11:31] git add [11:31] [hackman@localhost foobar]$ git diff [11:31] diff --git a/helloworld.txt b/helloworld.txt [11:31] index 9b58a54..8c78f82 100644 [11:31] --- a/helloworld.txt [11:31] +++ b/helloworld.txt [11:31] @@ -1,2 +1,2 @@ [11:31] -Snapshot [11:31] -1 [11:31] +Snapshot 1 [11:31] +Snapshot 2 [11:32] $git add helloworld.txt [11:32] sayan: BhaveshSGupta: will look like this [11:32] raydeeam: use a pastebin if you are pasting more than 3 lines [11:32] next [11:32] git add helloworld.txt [11:32] okay [11:33] yes [11:34] as gargantua_kerr[m and iinternaut said it's git add helloworld.txt [11:34] so move the changes to staging area [11:34] and see what is the output of git diff --staging? [11:35] error: invalid option: --staging [11:35] ! [11:36] Error [11:36] oops [11:36] $ git add --staged [11:36] ^^ this is the command [11:36] next [11:37] git diff --staged [11:37] ^^ sayan ? [11:37] error: unknown option `staged' [11:37] resolved now [11:37] Same as previous [11:37] eh [11:37] Diff [11:37] Same as previous diff [11:38] BhaveshSGupta: yes [11:38] iinternaut: gargantua_kerr[m what version of git are you using [11:38] git version? [11:38] sayan, maybe you meant `git diff --staged` [11:38] sayan: 2.17.1 [11:38] oh yes! [11:38] git diff --staged [11:39] works, but don't see any output tho [11:39] Yeah so it should show you the diff that was shown in git diff [11:40] yes it shows now [11:40] gargantua_kerr[m: did you do git add helloworld.txt? [11:40] now this is diff that would go into the next commit [11:40] sayan: Yeah, now it shows [11:40] when you do $ git commit -m "Snapshot 2" [11:41] when this is done, you can check the logs/history using the command [11:41] $ git log [11:42] this would show the commits that you have done till now, for us it's 2 [11:42] any questions till here? [11:42] no [11:42] No [11:42] no [11:42] no [11:43] Any one have issues if I do classes tomorrow? [11:43] sayan: timing? [11:43] I'm not sure. Morning I will try [11:43] Nope. [11:43] No issues. [11:44] yeah morning will be fine [11:44] no issues [11:44] no issues early morning, I have a group meeting at 11am [11:45] no issues [11:45] I will update the timing in the calendar by night [11:45] ack [11:45] but if i wont be able to make it i'll ask around [11:45] iinternaut: I will try not to collide with 11am [11:45] and so that you can attend the class [11:45] Roll Call [11:45] Thank you very much sayan :) [11:45] Rayan Das [11:46] Abhay Kaushik [11:46] Nilesh Patra [11:46] vibhor [11:46] Pallav Bhalla [11:46] Bhavesh Gupta ----END CLASS----