----BEGIN CLASS---- [04:30] #startclass [04:30] Roll Call [04:31] Aniruddha Basak [04:31] Rayan Das [04:31] vibhor [04:31] Nilesh Patra [04:31] so yesterday we had done our 2 commits, right [04:31] any questions from tomorrow? [04:31] oops [04:31] yesterday [04:32] Okay, since we have no questions let's move ahead [04:33] yesterday you noticed that we added a file using the command git add [04:33] when we do git add the files comes from untracked to tracked [04:33] the first time you add the file, it directly goes from untracked to staging [04:34] and if the file is already tracked, and is in modified, then the file goes from modified to staging [04:34] so, we can deduce that git add moves files to staging area for the next commit [04:34] now, let's try it out [04:35] go to your foobar directory [04:35] $ vim hellomars.txt [04:35] Add the content, "Hello from Mars" into the hellomars.txt file [04:36] And add content, "Hello from Earth" into the helloworld.txt file [04:36] then do: [04:36] $ git status [04:36] tell me what do you see? [04:37] since the output would be big, you can use https://paste.gnome.org/ [04:38] https://paste.gnome.org/pfiq5ydhg [04:39] https://paste.gnome.org/pkohuir4j [04:40] so we see that the new file that we added is in the untracked section [04:40] and the file that was in modified, is in the section where git is tracked the changes [04:41] now there are various ways to move the files to staging [04:41] 1. git add . [04:41] dot (.) after git add adds all the files in into staging [04:41] but the issues with this is this might add unwanted files too into the staging [04:41] and by mistake you might commit the files [04:42] these files could be swp files of vim, cache directories of Python, or just some random file you created for testing [04:42] so it's always good manually add those files from untracked [04:43] 2. git add [04:43] so we manually check in the files into git for tracking [04:43] we do this one by one, and could be time consuming [04:43] ! [04:43] ! [04:43] next [04:44] git add * also does the same? or is there some difference? [04:44] iinternaut: so git add * , I guess would fall into second section [04:45] of git add [04:45] but here * means include all files [04:45] so it works like git add . [04:45] ! [04:45] so, I would say to refrain using it [04:45] next [04:45] if I've to move two files to staging file1 and file2 then git add file1 file2 will do that right? [04:45] raydeeam: yes [04:45] Ok [04:46] but you need to type or copy them one by one [04:46] you maybe not need to execute the git add command multiple times [04:46] but need to copy those files manually [04:46] git add file1 file2 file3 ... filen [04:46] next [04:46] Is there a command to just add file to stage which are currently tracked. And not to add new. [04:47] ! [04:47] BhaveshSGupta: yes, that I was coming after this [04:47] next [04:47] If I by mistake add a file to staging. How can I revert that? [04:48] so in that case git is very helpful [04:48] most of the things I learnt was by studying the things git spits out [04:48] https://paste.gnome.org/pkohuir4j [04:48] check the link that you pasted [04:49] you would see this line: (use "git checkout -- ..." to discard changes in working directory) [04:49] right? [04:49] yes [04:49] so if you add file1 by mistake [04:49] then do git checkout -- file1 [04:49] then git would move it back in appropriate place [04:50] if it was in untracked then it goes to untracked [04:50] else modified [04:50] got it? [04:50] yes [04:50] so something you should follow is what git tell you [04:51] you will also see (use "git add ..." to update what will be committed) [04:51] so, every command tells you somethings, you can follow and try those [04:51] moving ahead [04:51] 3. git add -u [04:52] I use this in 95% of the case, when I have made some changes, and all the changes are in modified [04:52] and I want to move all of them to staging [04:52] then just do git add -u [04:52] ! [04:53] ! [04:53] it will ignore the untracked and just add the modified ones [04:53] next [04:53] next [04:54] https://paste2.org/KwHOAEef [04:54] sayan: I think git checkout -- file will discard the changes instead of moving to unstages. I tried it here: https://paste.gnome.org/p7jnbh9sb [04:54] why does it still show hellomars in changes to be commited [04:54] oh [04:54] sorry [04:55] I told wrong [04:55] git checkout -- removes all the diff in modified and reset to the state of last commit [04:55] but can you tell me the correct answer? [04:56] iinternaut, me too [04:56] git is telling you what to do [04:56] "git rm --cached ..." [04:56] (use "git reset HEAD ..." to unstage) [04:56] do you see this in https://paste2.org/KwHOAEef [04:56] sayan: git reset HEAD [04:57] so git reset HEAD hellomars.txt should do the trick [04:57] sayan, yes [04:57] gargantua_kerr[m: yes [04:57] try ti [04:57] showing me this https://www.irccloud.com/pastebin/g9z9obHc/ [04:57] try it! [04:57] got it now [04:58] aniruddhab: Did you commit helloworld.txt yesterday? [04:58] no [04:58] This is my first class [04:58] aniruddhab, it's because those are untracked files [04:58] aniruddhab: yes, that's the issue [04:59] Then i have to commit those [04:59] so you just added them, so git rm generally removes the files also [04:59] git rm does opposite of git add [04:59] ok [04:59] ! [05:00] removes the file from tracking [05:00] but if you do git rm --cached, it removes the file from git tracking but does not delete the file [05:00] next [05:00] sayan: But git rm removes the file itself too! [05:01] I used git reset HEAD , but now git status is not showing that file in Untracked files [05:01] sayan, ok understand [05:01] gargantua_kerr[m: yes, that's why the --cached [05:02] https://paste2.org/3N4ajsME here [05:03] hello.txt is in directory but not showing up in Untracked files [05:04] iinternaut: I'm not sure [05:04] is it possible that you have a global gitignore somewhere? [05:04] Nope, sayan [05:05] lol I don't even know how to set that [05:05] iinternaut: check git status --ignored? [05:05] Same output [05:06] Hmm, let see after the class [05:06] iinternaut: Did you by any chance commit it? see git log [05:06] Yeah that could be [05:06] okay [05:06] I'm thinking of same [05:06] gargantua_kerr: no, last commit is of yesterday [05:06] oh [05:07] got it [05:07] yeah, after reverting changes [05:07] iinternaut: git diff hello.txt? [05:07] cool [05:07] through checkout [05:07] it is same as last commit [05:07] this is what happens when you don't follow instructionms [05:08] Yesterday we committed only helloworld.txt [05:08] hehe, sorry sayan [05:08] next [05:09] so as of now, we should have helloworld.txt in modified (after 2 commits) [05:09] and hellomars.txt in untracked [05:09] can we all come to same stage? [05:10] yes [05:10] Yes [05:10] tell me when you are [05:11] Yes [05:11] yes [05:11] now as I told [05:11] we will be careful and manually add untracked files [05:11] so git add hellomars.txt would move the file to staging [05:12] and to move helloworld.txt to staging we do [05:12] $ git add -u [05:12] then do the commit [05:13] git commit -m "Add the file hellomars.txt and update helloworld.txt" [05:13] tell when done [05:14] ok [05:14] sayan: $ git add -u will move only helloworld.txt to staging, right? [05:14] gargantua_kerr[m: yes [05:15] Done [05:15] done [05:15] done [05:15] donw [05:15] Done [05:15] moving ahead [05:16] now how do we browse logs? [05:16] Git log [05:16] git log [05:16] git log [05:16] right [05:17] so if you do [05:17] $ git log [05:17] by default, with no argument we see the commits in the repository in reverse chronological order [05:17] the most recent come up first [05:18] the command lists with it's SHA-1 checksum, it's author name, email and the commit message [05:18] right? [05:18] Yes [05:18] yes [05:18] Date is also there [05:18] yes [05:18] yes with time+zone [05:19] Date: Sun Jul 21 10:44:20 2019 +0530 [05:19] right, you will also have datetime and timezone [05:19] now there are various other parameters that you can use [05:20] git log - shows last n commits [05:20] we have 3 commits so do [05:20] $ git log -3 [05:20] or better [05:20] $ git log -2 [05:21] do you see the expected output? [05:21] yes [05:21] Shows last two commit. [05:21] yes [05:21] yes [05:21] cool [05:21] Yes [05:22] next, you can see the difference in each commit using -p or --patch argument [05:22] I use probably everyday [05:22] do git log -p [05:22] you would see the diff introduced in every commit [05:22] you can also combine args sometimes [05:22] like [05:23] $ git log -p -2 [05:23] would show last 2 commits diff [05:23] understood? [05:23] yes [05:23] Yes [05:23] yes [05:23] Yes [05:23] this is very helpful when doing reviews of other people [05:24] or just want to see how a file was build [05:24] git log helloworld.txt -p would show that [05:24] try to mix and match and see how it turns out [05:25] if you want to see abbreviated stat for every commit, you can use [05:25] $ git log --stat [05:25] helloworld.txt | 1 + [05:25] 1 file changed, 1 insertion(+) [05:26] do you see something like this? [05:26] yes [05:26] sayan: I get : fatal: option '-p' must come before non-option arguments on going $git log helloworld.txt -p [05:27] Yes, but got log helloworld.txt -p gives error [05:27] git log -p helloworld.txt [05:27] (this is what happens when you overuse autocomplete) [05:27] (you = sayan) [05:27] :D [05:28] everything's good? [05:28] Yes [05:28] yes [05:28] I will end the class here [05:29] next day, we will start of working with branches, and remotes [05:29] home task: [05:29] - Read https://chris.beams.io/posts/git-commit/ [05:30] Thank you very much, sayan! [05:30] Thank you Sayan [05:30] - Read more about git log and write a blog on it, like `--since` `--author` etc [05:31] okay [05:31] and this is must, there will questions asked in next class [05:31] Roll Call [05:31] Ok [05:31] Bhavesh Gupta [05:31] Rayan Das [05:31] Aniruddha Basak [05:31] Mrinal Raj [05:32] Philemon Johnson ----END CLASS----