Intro To Git: Learn the foundations of Git and version control | Learn with Dr. G

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome back to another episode of learn with dr g that's me i'm really excited because we are finally starting the what you didn't learn in school series where we're going to be talking about different things um that sometimes are assumed when you're taking a formal class that you might already know now there's a lot of resources online for them but sometimes it's useful to just kind of get a guide through that so we're going to talk a little bit about that um today and for the next couple streams so stick around [Music] as always i want to remind you of our code of conduct essentially we just want you all to be kind and friendly we are all here to learn um and just have fun and form a community hello everyone um nice to see you all awesome and yes i can see the chat for everything so if you're watching on learn tv or any of our youtube channels or twitch um i can i can see you all so feel free to ask questions or make comments so today we're going to be kicking off this like mini series with the introduction to get so this learning path here which you can find at aka ms slash run with dr g slash intro to get um this is the first module in a short learning path where you get introduced to the basics of git which we'll talk about today so if you have questions about it please be sure to ask um and i'm happy to to help out over the next couple months actually we're gonna be diving into git github some vs code extensions powershell bash wsl which is the windows subsystem for linux and some apis and possibly some arm so yeah i'm really excited about it hello everyone hello to brazil nice to see you all so if you want to follow along with this um you can head over to aka dot ms slash dr g slash intro to get um and we're gonna uh jump into kind of the exercises in a bit here um but you're welcome to follow along uh you don't need anything else installed for this stream everything can be done inside of your browser as long as you have a microsoft learn account so an account it's free it's a microsoft account you can sign in to learn with your microsoft account and you should be able to use everything hello to china good afternoon all right as i mentioned this is part of a mini series on what you didn't learn in school and um i did create this short little playlist here for um different all of the videos that are going to be in this mini series will be in that short playlist so if you want to uh follow along kind of in the whole series and the videos you can do that by heading over there okay and that's it learn with dr g aka ms slash dr g slash w-y-d-l-i-s what you didn't learn in school underscore videos hello from the other side we shouldn't let me start singing okay so let's talk a little bit about git i'm going to be taking a look at the comments um and kind of just trying to chat with you all so let's talk a little bit about git and what git is um maybe you already know some of this and if you have some additional information feel free to put comments uh put put put info in the comments um and we can all learn things together so git is essentially an a way to one of the primary ways you use it is to collaborate with others on software projects on code it is also extremely extremely useful for projects that you're doing yourself i don't know about you but when i'm kind of building a large project that's going to take more than 10 minutes of me sitting at my computer there's going to be different parts to my project that i'm thinking of i'm gonna have different points at which my project is kind of like a checkpoint where it's kind of complete enough um and it's working and then i'm gonna start on like a new feature or a new part of it right so the way that i like to develop software is always thinking about that um now i just uh there we go that mvp i was gonna think mvp and then i started thinking the mvp mvp program at microsoft and i'm like that's not what i'm trying to say it is mvp the most sorry least most least filed out least file most minimum what does the m stand for minimum viable product there we go mvp minimum viable product um i'm going to put that in a banner mvp minimum minimum viable product um the reason i like to think about it like that is i was a part of a startup um i also was in grad school and then i also worked at larger software companies and inevitably deadlines always crept up and so rather than trying to cram in to meet some kind of deadline um that definitely existed and was very important i always made sure to have multiple points where i could kind of stop and say at the very least this works this can be shipped maybe some features are missing maybe it's not exactly what i wanted but the very least this is a complete functional piece of software so that's always how i like to build software and um uh awesome if you know how git works and you can't sleep please help others learn too thanks for joining um yeah we got there eventually buffering exactly that's me all the time um so i always like to make sure that i'm kind of at that point and git is just kind of the way that allows me to ensure that if for some reason i got to that point and then i started you know going on to the next part and ran out of time i could always just kind of ship that last point and rather than kind of having to save that code off to the side and then like copy it and continue working you can use something like it essentially get is version control so it is controlling it's kind of like understanding at every every version of every file in your entire project it is very much focused on files not necessarily like directories and we'll kind of get into that in a little bit but really focused on files and like i said you can use git completely on your own on your own machine nothing else you can use git kind of in collaboration with servers such as github is an example of a hosted git that you can then connect with um and yeah that's pretty much how you can use the two uh and then oh sorry so you can use it in collaboration with like github for example which we'll get to in a later stream and you can use it with other people so on one computer by yourself with a server by yourself with a server with other people i guess technically on your computer with other people but that's just kind of strange because if you're all on the same computer you don't really need it um not only do you kind of get those checkpoints but you also get to add additional information about where you are when you're making those changes and kind of what those checkpoints represent it also lets you quickly be able to see what changes have happened since the last time you looked at a particular file which especially if you're working with other people is very useful but even if you're working with yourself just on a project by yourself um and you've let's say made some changes and you forgot what you had set that um like random number to but it worked that one time and it's not working now and you can't figure out why you can kind of do a diff and see those um all right i'm reading some of these yes so uh a solution for version control for things that are kind of more than code that can get kind of tricky there are i don't know all of the kind of solutions here there are some support in get four non-code programs um but you kind of need an additional layer where you kind of turn it into something that is essentially text based and not like object based um i've actually seen the ability to have like diff files on images for example and we can look into that in the future too all right it also helps if you can get blame people yes um we'll talk about that in a future episode as well all right so version control let's kind of talk a little bit about how version control works um there's in this learn module there are a bunch of these three letter acronyms or tlas um tlas that's i i learned that term when i started working at microsoft um it's like a pretty much i can't remember how to spell acronym does it have an extra n at the end no it doesn't okay for some reason i thought it did um i thought that was pretty funny because tla is a three-letter acronym and those can get confusing so if you've ever heard of vcs that's essentially a version control system if you've ever heard of c v s that is a um control sorry concurrent versions system you might have heard of s c m which is a software configuration management you might have heard of s v n which is subversion yeah cps it's a pharmacy that's the first thing i think of or perforce um so all of these are different types of version control systems however things like cvs svn and perforce are actually centralized server types of version control systems where all of the code always exists on the server and you don't have this kind of local copy so every kind of all of the source of truth is on that server so if for some reason you lose access that or you know it goes down then you have that single point of failure git on the other hand is distributed which means you essentially have a server or you could have a server that has the source of truth but then you could also have a local copy that's your own source of truth and everyone else who has access to that project can also have a local copy that is their source of truth um and then you can decide how you want to relate all of the above we'll get into that when we talk about github as well so one of the best ways to think about git is and i think i've got this image here that i wanted to bring up so um let me just walk you through this really quickly there is this great website um which is basically the get documentation website it's at get um dot s sorry dash s goodness gracious get dash scm i hate three letter acronyms dot com hello um so you can head here and um someone was asking how many participants are on the learn tv so i got distracted i was trying to check the comments for learn tv i'm not sure how many are on right now but nice to see you on learn tv um so the git documentation has amazing documentation that you can walk through it's got this reference manual and essentially like a book and a bunch of videos so you can go check those out um one thing that i like to look at is this one here so this file right here this page right here kind of walks you through what files could look like at different versions um and uh like where you have my you might have a working directory a staging area or your git directory which is the actual repository so you might on the server have your git directory you would check out the project to your working directory which is on your local machine then you would stage fixes to the staging area and when you're ready you would commit all of those fixes to that working directory we like to call we'd like to reference trees when we're thinking about git because that's kind of how we think about it we have this one source of truth that is the git directory that's typically on the server and then you can have multiple people have branches off of that tree and each branch represents kind of a version of that directory and then you can kind of bring it back up i forgot to bring this one up um but there's a github um how github works um page that i absolutely love and i'm sad i didn't have this where did i find it again why can't i find this github.com um and then you can go to it's like on the about i don't know i'll try to find it in just a second um but essentially it's we kind of think about it like a tree um all right sorry reading through this is this the first episode yes this is the first episode of the what you didn't learn in school focusing on git um push pull commit yes wait push pull commit pull commit push maybe um i am not talking about xbox controllers um yes git allows us to be more agile and um where lives staging area ram or hard drive oh good question i mean it lives on your hard drive um for sure because it's actually stored on your local machine i mean things will be brought into ram as you're working on them but there's another um picture no there isn't another picture uh yeah so we kind of think about these working trees because that is going to be that main project that you're working on um and your working tree is basically that or sorry your repository is basically that high-level directory that has all of your files in it that then contains all of your working tree one of the best ways to see this is to actually do it so in the future on this mini series we're going to talk about the get integration with visual studio code and also with github and other github tools like github desktop but for now we're going to actually jump into what is called the sandbox in microsoft learn push from the working copy pull fetch from local repository yeah we'll get into the language in just a second so this is a really great resource for you again this is going to be on the um learning path which you can find at uh aka ms slash learn with dr g slash intro to get so if you want to follow along and do this as well um we can do that oh there's a link right there um perfect and then uh we're gonna activate this sandbox and this basically uses azure cloud shell to give us this interface on the right hand side that's not only going to give us a terminal but also allow us to open a version of visual studio code all within our browser it's not that github code spaces this is just an integrated experience with microsoft learn which you'll see in a second um yes there will be a schedule for streams for the next episodes um and actually you can find that at on my um i'm trying to do this uh effectively but you can go to um github.com where i am trying to um have this be clear so that you can you can kind of keep up to date with what's going on uh so here are a couple and i plan on adding more in the future so once our sandbox is activated you can have up to 20 sandboxes each day and you get two hours per sandbox when you initiate them or activate them so i'm using sandbox number three for today um because i obviously wanted to make sure that i was testing all of this out um before the stream also all right so right now we've got this this terminal over here and if you're unfamiliar with the terminal basically this is a text based version of your files on your computer so um right now if i type in ls that means list like list all of the files so that's the equivalent of double clicking and looking at a folder in the contents of a folder we're going to follow through this right now this is just a temporary machine it's not something that you can have access to later it's just for the purposes of testing um the github client for windows yeah we'll talk about github in a future one i really like github desktop which works on windows mac and linux um and yeah i love this as a sandbox for trying git commands it's one of my favorites and i'm so glad that they integrated this into that um and yes i i also love mac users i i'm an all of the above user all right so get dash dash version will just ensure that we have a version of git installed um so if you haven't installed it already on your local machine and you're trying to do this on your local machine not in the sandbox then you need to make sure you install it and then you always want to make sure you know what version you're working with and always update when you can't so the next thing that we're going to do is we're going to configure git and this is important because um if you're going to commit code to a repository to a git repository then you need to be able to uh sorry git needs to be able to assign that commit which we'll talk about what a commit is in a second to you and your email so then that way if something goes wrong people know who made that commit okay um so the first thing that you always want to do when you're setting up git on your local machine is set your configuration file specifically your name and your email so um i'll copy this and paste it oops how do you paste in the paste in here yeah there we go and we'll go ahead and change this to dr g and then we can set our email and since this isn't actually real i'm just going to say drd email.com perfect again you want to put your real stuff in there when you're doing this for real on a real project uh for this purposes it's not going to go anywhere so we don't have to worry too much um sorry reading through this pick the computer in os that suits you 100 agree definitely um for people who didn't understand vcs uh i think i missed your first comment um version control system yes that's what this one is all about oh here we go uh centralized version control system are characterized by a privileged repository managed by a server yes that's a great explanation thank you for helping is sourcetree a bad thing um i don't think so i actually can't i can't remember um awesome thank you muhammad for adding additional comments um if you're watching on that same youtube channel uh um great explanation thank you so now that we've configured git so that it knows who we are we're ready to start writing some code and seeing how git handles our code so again remember the point of git is to have a source of truth and to be able to track changes that are relevant and then to be able to kind of go back and forth between those changes so in this example the first thing that we're going to do is we're going to create a directory called cats so mk der mkdir means make directory and that's the equivalent of creating a new folder right so meaning list you can see that i do have this cats folder right here and i didn't have that before then i'm going to go cd cats cd is change directory so that's the equivalent of kind of double clicking open into a directory or folder and now you can see that i am in that directory called cats whereas before i was in my home directory which is represented by this tilde so in order to tell git that we want to track any changes that are happening within this folder aka repository we need to type get init so that's going to initialize this folder as a git repository all right hello everyone all right we'll continue another really useful uh command and one that you would probably use pretty often is called git status and let's kind of zoom in down here so we can see this a little bit better so git status will tell us the status of our local copy in comparison to what has happened since the last time we have synchronized with the um kind of source or source of truth so for example we are currently on the main branch we have not made any commits yet and we have not made any changes to our local files that we might want to commit notice that it does give us this little kind of snippet here that says that um if we do want to create and or copy files then we might want to do git add git add is going to tell git that that file that you're going to add is one that you want it to track so now it's going to pay attention to that file and anytime you make a change to that file it's going to show up down here to say hey you've made a change to this file you might want to consider committing it how can you move up one folder great question if you do cd dot dot slash cd dot dot slash like this and that says go up one directory if you did that and typed ls we can see that sorry let me really scroll down i think it's because i'm like a little bit um now you can see that we're at that top one if we did pwd that is what is our path of our working directory pwd path of working directory so the working directory that we're in right now is home slash sarah and when we did cd cats our path of our working directory was home slash sarah slash cats you can do ls minus a which gives us also shows us all of the hidden files within our directory so do you see the the um the dot is our current directory the dot dot is the directory above and the dot get is a hidden folder that contains all of the things that git is kind of like paying attention to basically contains that all right if you type get dash dash help you will get all of the get commands that are most likely going to be useful for you there's a bunch of other things that you can check out on that get dash scm.com documentation website um but this is also just a really useful thing in case you're forgetting some of these commands when we go over to the next unit within this module um it's not going to show us the sandbox but when we go to the other one that does have the sandbox that's when we're gonna get into um or it'll it'll save kind of your progress between them how to delete a folder we are gonna do that in just a minute what is the equivalent command for ls-a for windows um good question it's uh dir let's see are you in powershell um check this out equivalents for common linux bash commands looks like this might help i'm not exactly sure i even when i'm on windows i actually use wsl um so then that way i can stay in in a in a bash uh command prompt but um yeah you can you can take a look at that one is it possible to have multiple emails in the git configuration oh great question um yes i'm pretty sure you uh can you i'm pretty sure you can um i i think i've done this before multiple emails in git config let's see i'm using it with multiple emails it is a problem because then it can't um kind of do that but yes it does look like you can have a particular directory um that has its own git config file that has one type of email and then a different directory with a different git config file with a different email yes definitely can link this page great question and then i think you might have been asking for that other page oops this one those are the two i just found okay so let's talk a little bit about what we can do with git so right now all we've got is this folder no files in it yet and we're going to write some um html and css files in just a second super basic stuff um and then we want to start to understand how it's connected up with our git repository so we know that git status will tell us kind of the status of all of the things that have happened on the um like hosted version uh within our local version that we've committed and then things that we've changed that we haven't committed we saw that git add will tell git hey this file that i want to add pay attention to this one because anytime i make changes i want you to remind me that i probably want to commit it and then what is a commit so if we go back to um the git source code documentation we can actually see that this staging area here um sorry this is staging fixes um so committing basically says that so if you've made changes right so you've saved things when you commit it's still on your local machine okay but you're saying that that is a change that you want to save like this is data that is safely stored in your local database not just in that file but in your get your git now knows about this and if you made changes so let me let me say this a little bit better write code make changes commit those changes git now knows about those changes over here i'm going to keep writing code and save on my computer then right here i'm like oh no i messed up all of this code right here totally messed up with that i need to revert my code back to this point and instead of doing undo undo undo and do i can just go over to git and say hey can i get that code again and i can revert my code back to here and so git still knows about this and then i can kind of get rid of all those and restart does that make sense and you can do that with multiple right so we can actually kind of draw this out a little bit um if you have a file and then you make some changes i'll put changes in red right and then you commit that file so git now has that file with those changes and then on your machine this is still your machine though you can you make some additional changes and then you're like oops nope did not want that nope nope then what you can do is you can say hey you can i please have you can i have that back and then it'll say yeah no problem and it'll give you that it's basically what i'm trying to say and we'll see that in action we'll see that in action in just a second ah now i've got marker all over my fingers that's okay um yeah so ctrl s is like saving it to your local machine and a git is like control s for git it's a great way right um awesome thank you all right let's keep going a couple other commands git log will just give you a log of all of the commits that you've done in the past and then we already saw get help so yes no problem until merge conflict don't worry we'll get to those in the future so we're back to our azure cloud shell again look we still have our uh an hour and 44 minutes of our sandbox so that's good so now what we're going to do is we're going to actually create a new file called index.html and one way that you can do this in azure cloud shell is just by doing saying touch index.html and um you can see here an explanation for what this does so it either updates the last modified time um that can be useful for a lot of reasons but basically kind of like the relevance of that file um or it creates an empty file if the file does not exist which is what we're going to use it for so we'll type touch index dot html let me get rid of this banner so you can see a little bit better sorry that it's like it's hard to zoom in here with um oops with the um kind of see that a little bit better um so we do touch.index.html and now if we do ls to list we can see we have an index.html file if we did git status here its status will tell us the status of kind of that repository so let's go ahead and check that out so what we can see here is that with that we are currently on that main branch we still have not committed anything right we created this file but we did not commit that file all we did was create it and we have untracked files index.html is an untracked file because we haven't even told git to add it to the list of files that it's watching yet okay which means we cannot commit that file because git doesn't know about that file right even though that file is new and a change it doesn't know about that file so we can't commit it yet we have to add it first all right just checking in the on the comments perfect okay so next we're going to say git add dot bit add dot and this is one way that you can add all of the files in your local and that your current working directory or your current folder add all of the files to git to track them so if you remember up here when we said ls oops oh my goodness where did you go oh my gosh did my i think i just closed my window awesome i don't know how that happened all right let's go back to here i don't know how that happened but in any case still trying to sign me back in um when we did ls-a when we saw that dot dot dot and then the cats folder that dot is our current directory um so we've got that i think this is still the same sandbox um so i'm hoping that it loads it up again same one i'm not sure if it will so when we do git add and then space dot um then we can add everything in that fi in that folder but you can also do git add and then a specific file so let's say that you had a bunch of files that you weren't quite ready for git to kind of pay attention to or even some that you you didn't want them to you can specifically add certain files instead of all of them hello okay yay we still have cats and we still have get in there and let's do git status okay so now when we do git status again what we can see here is we're still on that main branch we still don't have commits but we now have changes that can be committed so earlier we had untracked files that could not be committed now we have a new file which is a change this is that new file and we can actually commit that change all right what if you wanted to add an empty folder yeah we're actually going to do that so we'll do that in just a minute um the next thing that we're going to do first though is we're going to actually make a commit so we've made a change right now index.html has nothing in it it's just an empty file um so we're going to say git commit index.html dash m create an empty index.html file so what this is doing right here is where it's telling git to make this commit of just this file there is a way that you can actually do everything in your entire directory if you wanted to so make a ton of changes and then commit all of those changes at once but for now we just have one file anyways and then this dash m is to say i want to add a message to this commit it is always always important and oh my gosh i can't tell you how many times i've been like oh the message isn't that important i'm the only one working on this my message is going to be something like like made a change another change small change and it's so unuseful because then 20 small commits later when i can't remember where that one thing is that i changed that one time i can't find it so have commit message i promise you i promise you it'll be useful how commit messages that are real okay so in this case create an empty index.html file so we'll go ahead and run that and if we did get status now um what we can see is we have uh committed this one file was changed there were no insertions and no deletions insertions are like characters in a file that you've added deletions are characters in a file that you've removed and so this is an entire file that was changed like one new file okay um and for git status we are on our main branch and there's nothing more to commit and we're working on a clean tree so since this is doesn't have a server attached to it like a server version we'll get that to that when we do github for example um once you commit it's already kind of stored in git and you're pretty much done you can actually add directories there is a way but we'll we'll kind of get there um yes so if you wanted to do all of the files in a directory um you just do dot although there is nothing in there because we haven't made any changes yet yep exactly git commit dash r so here we can find all of the get commit options so um sorry it's dash a not dot um dash a stands for all so am would be all of them so right here it wasn't dot i mean i think you can maybe do something you would do dash a so dash a would be all of the files that you have already told get to keep track of so if you did a git add to all of those files get dash a will do all of the files that have changes that you added to get okay yes the tree structure of git um we're gonna i'm actually gonna have a video of that on friday coming out where i'm gonna have some animations and show it better than me drawing things on a whiteboard that you can hardly see um so we'll get to that one look out on friday it'll be in that same um it'll be in that same playlist this one here um so if you are interested in checking out the tree structure of git um that video will be coming out friday all right one thing that we haven't done yet is git log so again like like i said earlier git log basically just tells us all of the commits that have happened so this is that hash for that commit it was committing from head to the main branch this is who made that commit and this is when it was made and this is what the commit message was and when we do more we'll be able to see more of that so now let's go ahead and open up our index.html file like i mentioned earlier you can type in code index.html and that's going to open a version of visual studio code as you can see it's not all of visual studio code but it's kind of this version so you can at least make some changes so we can add in some html here do control s for save or click on this and do save and then close our editor and now when we do get status we have some changes that were not staged for commit yet we modified index.html it's no longer a new file because it already knows about the file so we modified it so here is where we can say git commit dash a dash m adding a heading to html index.html so the dash a is going to say all of the ones that you've tracked you are tracking dash m is our message and we can continue to do that so now we're going to say code index.html and this time we're going to replace all of this with some better html and before we commit because git has a representation of our file and that representation has just that one header and i want to know my file that i have on my local machine because maybe i've been coding for like 10 hours straight i want to know what are what is so different about my file compared to that one just before i before i overwrite that one and i commit that one i want to know what's different so that's when you can do git diff and we can see here what gifted git diff does so right here we have in the file that is that git is tracking um we're going to remove this line of code and then we're going to add these 12 lines of code and notice right here it says that we're going to get rid of 1 and then add 1 through 12. okay and in later videos i'm going to show you with other ways of doing git diffs github for example has these really pretty ways of seeing it yes the get get commands there you go all right so that looks good that is the change i intended to make so i'm going to go ahead and commit that and we can do another get log and we can see now we've got multiple um commits that have happened this is the latest one and the one that is represented on our main branch but these are the other two that we did that the um adding the heading and then creating the empty file sometimes you want to be able to ignore certain files um i it's very important like sometimes there are meta data files that we really just don't want to keep track of because they're just metadata for your local machine and they're not useful to the actual project and in fact they might mess someone else up on the project or if you're switching between computers or things like that so one way of doing that is by creating a bit ignore file and this is a special git file that'll ignore anything with a dot b a k um and then also i think star tilde is like anything that is um uh uh like in in the home i'm not actually sure i can't remember what star tilde does now i'll have to look that up um i thought i knew and then now when i'm trying to explain it i can't remember in this case there aren't any of those um kind of uh backup files that's what bak is backup files um we're using git for that but we're not gonna have any right here so uh that's fine so let's go ahead and open up um our index.html again and let's change this one to furry instead of feline and close it and then let's do git add and git commit so not only are we making a small change the words but we're also adding in that git ignore file uh we needed to do git add dash a because we wanted to make sure that we captured that git ignore file so now if we did a git status and a git log of that and i shouldn't have committed before doing a diff but that's okay okay let's make another directory real quick we're going to call this one css rim swap files append tilde to the file name oh that's right thank you yep swap files i was like i remember that and then i couldn't remember what it was each commit should focus on one small task yes agreed um very good point each commit should should smoke us should focus on one small task it's fine if you modified one file or five um oh ms office also has temp files with tilde um it should be one specific task so then that way your commit messages are very clear yes temp files when we get into talking about github in later videos we'll talk about gits versus or sorry commits versus pushes versus pull requests which is kind of a whole another layer to it okay so this is where we wanted to create that directory so bit status notice that we made a directory but it says that there's nothing to commit so like earlier someone was mentioning can we commit an empty directory and someone was like no you definitely can't do that no you really can't do that but you can kind of do that if you create what's called a git keep file which is essentially a nothing file it just essentially is a file just to tell git that you really want to keep that directory even though it is empty you can actually create an entire file structure and have get tracked that file structure that's just completely empty but i don't know if it's depends on your use case cool uh my phds in computer science uh focusing on education so let's go ahead and remove that file though so someone else earlier was asking about removing a file so you can actually remove a file with rm rm will remove that file and now let's go into that folder and let's create a css oops um and let's go ahead and do that and then let's go back up to here and let's go ahead and add this into our head okay so now we've made some changes let's go ahead and add those change sorry start tracking the new file which is our site.css file um and then before we make a commit we can see kind of these diffs you can add a commit and now we can see all of these files here if it does show you kind of like a longer get and then you push it has the the colon on the side and then you push enter to kind of continue to see it you can click cue to escape from that and be able to um continue on in your terminal we can do get log dash one dash one line which will give us that git log in a smaller way and that's why these git commits are super useful for you all right the next thing that we're going to do super quickly is actually fix mistakes that we might have made so let's say you accidentally removed index.html now we have that css folder but we lost um index.html what you can do is say git checkout dash dash index.html so what we want to do is we want remember we just kind of like deleted this one now but we're in this point in time and we want to go back to git and say hey can can you hand that to me please can you bring that back all right and then when we do that our index.html is back all right um if instead of doing rm index.html you did bit rm index.html now you are actually removing index.html from git so now you kind of undid the ad which means if you tried to do git checkout index.html again git is like i don't know what you're talking about because you never told me to track that or you told me to stop tracking that so i can't help you there and that's where we might want to um reset our head which is gets kind of like main working tree branch we want to reset that for the index.html to what we currently have on our local machine because remember our local machine oh sorry we want to reset it to the previous commit and now we can check it out again and have it back um and then you can also uh um like make another change um so you can kind of continue doing this stuff here we can do that so we've replaced all of our code and then we say oh my gosh we're replacing all of our code we're committing that we're purposely overwriting it on accident um and then here we can look at the last bit log just the last one um and we can check out again and open it and we can see that that has all of our bad stuff that's our old stuff that's our mistake because we made a mistake we committed that mistake and then when we checked it out we're like oh no there's the mistake um so you can actually revert back again to a previous commit and then now um what happens if i'm running out of time so now i'm talking fast um but i'll finish talking about this in the video that i'll post on friday um so we made a change where we overwrit the contents um we tried to uh we checked out the previous commit so then um and and it was wrong right we're like oh no so then we said let's revert that i want to undo that i don't want that change there anymore so the newest commit is that we didn't we wanted to revert that change so now if we were to check out again we have our code back so checking out will just kind of give you whatever is at the highest level and then reverting will allow you to grab the previous commit message okay sorry i'm going gonna answer some questions super quick um i'm not sure how css is equal oh right so um i had css on mine when i was showing it i had it in lower case as css um and uh in this lesson it actually has all uppercase i just it would make a difference um but i am not uh we're not actually trying to run this code so it's it's it's all okay um difference between git checkout and git restore great question um i don't think i have time to answer that full question um but i'm going to write that one down as something that i should answer in the uh video friday is case sensitive yes um [Music] command to roll back to a specific commit yes i will put that one in there as well and yes it is so command to roll back to a specific git you do git commit and then a specific id so we can probably do that in here quickly let's close this editor let's do git log sorry let me do git logs ah i did this way too long ago there you go oh i put a space that's why um so this like hash right here um that's what you can use uh in order to get a specific commit so you can do a git um checkout or get revert to to those um yeah within the file so basically over here i should have that was my mistake this should be lowercase css um because i saved mine as lowercase or i created the directory as lowercase css that was a good catch um i should have not done that mistake um and squashing commits um i can't right now because i've got one minute left um but yes uh in the video i will add in um uh i'm gonna go through these comments and anything i couldn't answer i'll add some information in that in the next video and then also you can watch uh um the next couple of streams are still going to be on git so next tuesday and the tuesday after are all get related things so again if you wanted to check out um uh uh number one if you could please uh submit a survey for us so i know if this is conference that you all want um but from the comments i think it is so we will continue to do things like this um and then also um if you could oh if you have any other questions after this is over please don't hesitate to reach out to me um on twitter dr gussels hashtag learn with dr g and i will look through those and we can answer them in the next couple of streams otherwise thank you so much for joining i have to let go for the next stream but i'll talk to you all soon bye
Info
Channel: Microsoft Developer
Views: 7,807
Rating: undefined out of 5
Keywords:
Id: dnDHVbO7ycM
Channel Id: undefined
Length: 59min 41sec (3581 seconds)
Published: Tue Feb 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.