Python for Entrepreneurs Transcripts
Chapter: Digging Further into Git
Lecture: Git Staging and Committing
0:01 Now that we're familiar with the "git status" command,
0:03 we can start adding files to our Git repository,
0:06 Git has a two step process for committing files,
0:08 the two step process requires us to add files and then commit them.
0:12 First we'll visualize the "git add" and "git commit" commands,
0:15 and then we'll see an example on the command line.
0:18 Let's say we've got a pretty typical Git repository on your local system,
0:21 it's got a bunch of files and subfolders with files within them.
0:24 In most repositories there would be a README file,
0:27 maybe an app.py, something that contains your Python code,
0:30 and of course you want to make some changes to these files,
0:32 so you open them up in your text editor, you make the modifications that you need to,
0:35 in this case we'll say that README.md and app.py were modified.
0:39 Now what happens when you run the "git status" command?
0:42 Assuming that you have at least one commit in your Git repository,
0:45 you'll have a commit hash, this commit contains the most latest file changes,
0:49 excluding the ones that you just made to README an app.py.
0:52 So when we run the "git status" command,
0:54 it will say that there is untracked modifications to README an app.py.
0:58 The first step for us to get these added to a new commit,
1:02 is to run the "git add" command and point to README.md and app.py.
1:07 If we run "git add" with these two files, then the staging area will be updated,
1:12 and if we run "git status" again, these files are not yet committed
1:15 but they are part of the staging area and ready to be committed.
1:18 The next step would be for us to run the "git commit" command,
1:21 we don't have to specify specific files with the "git commit" command,
1:25 because, it's just going to take whatever is in the staging area, it's all or nothing,
1:29 when we run "git commit" and we give it a commit message,
1:32 it will create a new commit and that commit has a specific hash,
1:35 so for example let's say our new hash is 12ab0f1.
1:41 Now this is actually just the shortened version of the full commit hash,
1:44 the full commit hash is a much longer length, which we'll see in just a moment,
1:47 finally, if we run the "git status" command again,
1:50 it's going to say that there are no modifications to any files,
1:52 because the modifications that we made to README
1:55 and app.py have been committed to our Git repository.
1:58 Let's see what this looks like with an example project.
2:01 I'll run through an example of how I use the "git add" and "git commit" commands,
2:04 as part of creating the Full Stack Python open source project.
2:08 Don't worry about falling along for now,
2:10 we'll go through an example with the course demos,
2:12 Git repository in the next video, this example is just to give you an idea
2:16 of how these commands fit together.
2:18 I'm already in the Full Stack Python project
2:20 and we can use the "git log" command to see what the latest commit is,
2:23 I mentioned a moment ago that the hash was actually
2:26 a part of a much longer hash, this is the full hash for "git commit";
2:30 however the last seven digits are typically enough to identify a unique commit
2:34 within a Git repository, and most recent commit was done on December 19th
2:38 when I added some new NoSQL resources.
2:41 We're going to add another commit now.
2:43 However, there aren't any changes that we need to commit,
2:46 I am going to modify one of the files and regenerate the site,
2:49 so that we have some changes.
2:51 I'll use a text editor of my choice to open up one of the pages,
2:56 which is the change log.
3:02 I was fortunate enough to cross the 800,000 reader mark for the year,
3:05 so I'll add a little note about that in here.
3:15 So now this one file is modified, so if we type "git status", it will show us
3:18 that this one file is not yet staged to be committed,
3:21 however, I don't want to just commit this one file
3:24 I also want to regenerate the site
3:26 so that new HTML files are created from the markdown.
3:29 In order to regenerate the site, I add a shortcut command,
3:31 I just type "m" and it runs a makefile, which handles everything for me.
3:35 And now there should be three files that are modified.
3:39 The HTML file that gets generated and then the original markdown source file,
3:43 now, we can add these three files, I am going to change into the root directory
3:47 where all and change-log.html are located
3:50 and then I'll run the "git add" command with period,
3:52 period means add any files in the current directory or subdirectories
3:56 for a "Git repository", there is one flag you should know about,
3:58 in case you're deleting files and that would be the -A flag,
4:02 this includes everything when you're adding files,
4:05 including deleted files which are not normally added
4:08 unless you specify the -A argument.
4:12 If you already added files to the staging area, you can continue to add them
4:15 over and over again, and it won't change anything,
4:17 and it won't commit them until you actually use the "git commit" command,
4:20 let's do that now. We are going to use "git commit"
4:22 and we'll use the "-m" flag in order to specify a message on the command line.
4:32 Now we've added and committed some files, and if type "git status",
4:35 it's going to say there is nothing to commit and we can continue to work on new files.
4:40 So that's an example of how I use the "git status", "add"
4:43 and "commit" commands together to work on full stack Python and Byte Size Chunks.