Flags in Git Commit
There are certain flags in git commit like -a, -m, -am.
- Git commit -m “commit message”: A command that creates a commit with a commit message written under quotation.
- Git commit -a: The command only includes modification to the files that have been added with git add at any time i.e., all the tracked files.
- Git commit -am “commit message”: It is a combination of both the -m and -a commands.
If you now find that you accidentally left something out of your last commit, be it a file or an extra change to a file that you just committed, then you can fix that also. Let’s now make some modifications in the “file.txt” i.e., I write “Hello Crio” in that and now we have to repeat the process of add and commit.
After this, the file “file.txt” has been modified and you can check that using the git command git show.
If you want to view the history of everything that happens to a repository then you can use the git log command. A Git log is a running record of commits.
As you can see above there are two committing histories, let’s say you did a mistake in “file.txt” so you have the repeat the process once again and hence there is one more committing history generated. For the small number of history, it is fine, but if you are making mistakes several times and committing them then there is a huge number of history created and it is a bit confusing for the other developers when working with complex types of projects. So to handle that, git commit –-amend command is used. git commit –amend -m “commit-msg” where -m is a flag used for the commit message is a command used to doesn’t create another commit history and is just overrides the previous commit.
Here in the above image, you can see that there is no third history created. What did here is the previous commit is overridden and hence the commit history remains the same.
What is Git Commit?
Git is a distributed version control system widely used by developers to manage and track changes in their codebase. One of the most fundamental and essential commands in Git is git commit
.
This command is important for recording changes to a repository and forms the backbone of version control. In this article, we will explore what a Git commit is, how it works, and best practices for using it effectively.
Table of Content
- What is Git Commit?
- Role of Commits in Git
- Insert items from your Staging Area into your Local Repository
- Working with Git Commit
- Flags in Git Commit
- Revert Commit Changes