Git – Committing Changes To The Repository

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/git-committing-changes-repository/
PINTEREST
PINTEREST
INSTAGRAM

Previous chapter we have created our new clean repository but we did not added any code. In this chapter we will add some code and create some revision or versions of the code.

Getting Status of Repository

As we stated before we have a clean repository we can check this.

As we see status command provides some brief information about repository. We are on the master branch. We will look branches in the future. We have nothing to commit. Sure we have not added anything for now.

Adding Files to the Revision

Git have some fundamental steps to commit. We will look them through writing our app. Below we can find the natural flow of a commit.

Working Copy

We will create our app with the following code.

We have created a file main.py with single line code.

Review Changes

We have added some code to our project and want to see status of working copy. Working copy is currently used snapshot of the files.

As we see mail.py is under untracked files. Untracked file is a files that is not added to the commit operation. So If we want to commit our file we should add main.py into tracked files.

We have added main.py file to the tracking files. After adding file if we look to the status of working directory we can see that main.py is tagged as new file and there is no other untracked file.

LEARN MORE  Git - Environment Setup and Basic Configuration

Review Status Shortly

We can review status more shortly than default one.

  • status show the current working status.
  • -s show status shortly please

Show Diff of Changes

We may want to see more detailed information about like the diff of the changes. Here is the solution.

This is the code what is changed.

Skipping Staging

Staging can be skipped with simple -a parameter like below.

  • -a parameter make to skip staging which means no previous add needed

Commit Changes

We issue same commit command for git.

And we get following screen.

Following screen show information about commit and wants some words about commit from us. We add Start to the beginning of the screen and then close it.

And finally we commit our main.py . Was it hard? For now may be but after practicing it this is very simple procedure.

LEARN MORE  Git - Creating Repository From Scratch

Commit Again

We have worked on our project and added README.md file, changed the main.py to version 2. Now we have to commit again.

As we always do we issue a git status command to see current situation.

As we see that REAME.md is not tracked if we issue commit command. We need to it to the tracked files like below.

We have added the README file. So we can continue to commit.

We have commited more easily than before because we have provided the message .

LEARN MORE  Git - Branching Operations

Recommit and Change Last Commit

Some times we hurry up and make mistakes while committing. Here is the solution we can recommit our last commit

  • --amend used to update the last commit and new changes are added to the last commit.

Unstaging a File

Unstaging is removing a file from stage and it will be untracked.

  • reset clears specified file from specified HEAD
  • HEAD is current staged files status
  • LICENSE the file for unstaging
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/git-committing-changes-repository/
PINTEREST
PINTEREST
INSTAGRAM

Leave a Reply

Your email address will not be published.