Add and Commit
Run the following command in the terminal.
git status
You will get a list of untracked files.
The
git status
command displays the state of the Git repository.
Next, run the following command in the terminal.
git add .
Git now has taken a snapshot of the files in your repository. This is like pressing command
+ c
to make a copy in the memory (but the copy is not completed until you press command
+ v
).1
In Git's jargon, we say changes are staged to be committed.
You can run git status
now to see the state of our repository. The files in your project must appear in green color under "changes to be committed".
Next, run the following command in the terminal.
git commit -m "Initial Commit"
Git now has saved (committed) the snapshot you've created earlier using the add command. This is like pressing command
+ v
(after having pressed command
+ c
to make a copy). Commits are like versions of your repository where you can access at any future point. A commit is part of the history of your repository.
To see a log of your commits, you can run the following command in the terminal.
git log
The command git log
lists the commits made in reverse chronological order. Each commit has a commit ID (a hash identifier), the author's name and email, the date written, and the commit message.
You could alternatively perform all of the above commands from the "Git" menu in IntelliJ.
IntelliJ has a fantastic integration with Git out of the box to make your life easier! Learn more about it here.
Copy is not a great analogy because what is contained in a snapshot is mostly only the changes made.