1×
Become a member
to unlock all features
Autoplay

    Only commit some of my currently modified files into the repository

    Juri StrumpflohnerJuri Strumpflohner
    gitgit

    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

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss