When you create a new file or modify an existing one and you want to “save” these changes to the Git history, you have to “commit” them. Every change to one or more files can be “committed”.
A commit comes with a message explaining what and sometimes why something has changed. Please try to keep this message short and descriptive.
As a rule of thumb one commit should fix one problem, if it is a big commit you will find it can usually be split up into multiple problems and thus multiple commits.
Another rule of thumb is: “commit early and commit often”. This way you can keep track of your changes and even revert them if they need to be undone.
To see what files have changed you can execute this command:
$ git status
This will give you an overview of:
To commit a change you can use the following commands:
$ git add path/to/file
This command will “stage” the changed file for commit. You can stage as much files as you like, but keep in mind the rules of thumb discussed above.
Sometimes you accidentally stage a file that you do not want to stage. You can unstage the file with the following command:
$ git rm --cached path/to/file
To actually commit the file(s) you have staged:
$ git commit -m “Your descriptive short commit message”
The command above will commit your changes to the repository.
To see a list of the commits that are available you can use the following command:
$ git log
This will give you a list of commits containing the commit identifier which is basically a SHA-1 hash of the commit, the name of the author and the commit message.