Only commit some of my currently modified files into the repository

Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 5 years ago

You started working like mad on a dozens of different files and totally forgot to commit in between. Now it’s difficult to find a proper, meaningful commit message right? In this lesson we’re taking a look how you can individually commit just some of your files into the repository. Note: This only holds if you did not yet push your changes to the remote repository

Instructor: [00:00] I'm having here some sample project, which in this case is an Angular project. It doesn't matter, because what we would like to look now at is how we can commit single files into our Git repository. I've made a couple of changes.

[00:13] I've worked quite for a while, so I have changed here, for instance, in the app component. I've changed some HTML and some title here. Then, I've also added some files, some new packages to my application which then change here to package JSON, to package log file, and some other kind of files in my repository such as the index HTML.

[00:31] If you jump over to our terminal and do a Git status, we see all of these files that have been changed. Actually, I don't want to commit them all at once with a single commit message because there are different things I did here in this modifications.

[00:45] What I would like to comment is these two files, because I've actually changed some behavior of the app like changing the title. The other files, I would like to actually commit separately, because in those commits, I've actually added the new package to my application.

[01:00] Let's create the first commit. I can do a git add to add our files to the staging areas such that they can then be committed into our repository. Let's use the source app app.component.html as well as the source app app.component.ts file.

[01:17] I can commit these files individually by simply appending one path after the other two to get at command. I could also use wildcard. I could do the app.component*, which would then commit basically both the HTML and the TS part. Now, you can see these two are ready. They are in the staging area for my git repository. I could simply do a git commit -m and say feet, change to title of the app.

[01:46] Let's do another git status. Now we see those two fonts have been committed. We just have the remaining ones here in our repository left. Again, we could now selectively pick some of these files or rather do a git at dot for all of them, because they all belong to the same operation and do a git commit -m install Angular material.

[02:13] If you now do a git status, we see we have a clean history. Let's take a look at our log. We can now see we have a log for installation of Angular material and a log for the new feature of our app where we changed actually the title.

egghead
egghead
~ an hour ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today