Learning Git: What Is a Commit?
Learning Git: What Is a Commit?
Check out this article to learn more about Git commits.
Join the DZone community and get the full member experience.Join For Free
Commits are fundamental to Git, but not all developers have a comprehensive understanding of what a commit actually is and how it gets applied to your project.
In short, a commit is a snapshot of your Git repository at one point in time. In this beginner Git tutorial, we will dig into the journey of creating a commit.
You may also like: Top 20 Git Commands With Examples
Git: Working Vs. Staging Directory
To fully understand commits, we need to start by talking about your working directory versus your staging directory.
Your working directory is your active work area, and files created or modified here do not yet affect your project. When you modify, add, delete, or rename a file here, that change is not immediately stored in the repository. It only exists locally in the working directory on your machine.
In order for your changes to be reflected, you must stage them. Once file changes have been staged, they can be saved in the repository by performing a commit.
Each commit becomes a snapshot of your repository from that point in time, and all of your commits will cumulatively from your repo's history.
Git Workflow: Make, Stage, Commit
A typical Git workflow involves:
- Making changes
- Staging changes
- Committing changes
Making File Changes in GitKraken
When you modify, add, delete, or rename any files in your working directory in GitKraken, your Work in Progress (WIP) will display at the top of the graph.
When you click the WIP node, GitKraken shows you a list of the affected files in the Commit Panel on the right side of the UI, along with color-coded icons denoting the change type (modified, added, renamed, deleted).
Staging File Changes in GitKraken
GitKraken makes it quick and easy to stage file changes. Click on your WIP node and navigate to the Commit Panel. Simply hover over a file and click Stage File .
You may also click the file to view the diff, where you can choose to stage individual lines or hunks of the file.
Furthermore, entire files, hunks, or lines can be unstaged or discarded with the click of a button.
Discard all file changes to a given file by right-clicking and selecting Discard Changes, or discard changes to ALL files in your WIP by clicking the trashcan icon at the top of the Commit Panel.
Psst: Don't fear! The handy GitKraken Undo button has your back if file changes are ever discarded by mistake.
Committing Changes in GitKraken
Ready to commit? When you're satisfied with your staged changes, be sure to type a commit summary and description before clicking the button to commit your changes. You can also use the keyboard shortcut
Cmd/Ctrl + Enter .
This will transform your WIP node into a commit that can be clicked for future review of the changes made at this specific point in time.
Scroll through the central commit graph in GitKraken to see an overview of your project history, and click through other commits to review snapshots of file changes from other points in time.
If you enjoyed this video, to the GitKraken YouTube channel to stay up-to-date on all of our learning Git tutorials, and check out our Learn Git Center to see an extended list of our educational resources.
Published at DZone with permission of Jonathan Silva , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.