Commit (version control) explained

In version control systems, a commit is an operation which sends the latest changes of the source code to the repository, making these changes part of the head revision of the repository. Unlike commits in data management, commits in version control systems are kept in the repository indefinitely. Thus, when other users do an update or a checkout from the repository, they will receive the latest committed version, unless they specify that they wish to retrieve a previous version of the source code in the repository. Version control systems allow rolling back to previous versions easily. In this context, a commit within a version control system is protected as it is easily rolled back, even after the commit has been applied.

Usage

Git

To commit a change in git on the command line, assuming git is installed, the following command is run:[1]

git commit -m 'commit message'

This is also assuming that the files within the current directory have been staged as such:[2]

git add .

The above command adds all of the files in the working directory to be staged for the git commit. After the commit has been applied, the last step is to push the commit to the given software repository, in the case below named origin, to the branch main:[3]

git push origin main

Also, a shortcut to add all the unstaged files and make a commit at the same time is:[4]

git commit -a -m 'commit message'

Mercurial (hg)

To commit a change in Mercurial on the command line, assuming hg is installed, the following command is used:[5]

hg commit --message 'Commit Message'

This is also assuming that the files within the current directory have been staged as such:

hg add

The above command adds all of the files in the working directory to be staged for the Mercurial commit. After the commit has been applied, the last step is to push the commit to the given software repository, to the default branch:

hg push

See also

Notes and References

  1. Web site: 2022-06-13 . What’s the Git Commit Command? Our 2023 Beginner's Guide . 2023-11-27 . careerfoundry.com . en-US.
  2. Web site: The git add command for beginners . 2023-11-27 . www.theserverside.com.
  3. Web site: 2019-07-01 . GIT Push and Pull Tutorial . 2023-11-27 . DataCamp.
  4. Web site: Git - git-commit Documentation . 2017-10-04 . www.git-scm.com . en.
  5. Web site: Hg - Mercurial -Quickstart. www.mercurial-scm.com. en. 2018-11-05.