Creating a Git Commit
The git-commit
command takes accepts message (using the -m
switch) where you describe what the changes are contained in the commit.
$ git commit -m "adding new file"
[master (root-commit) 0542a0f] adding first file
1 file changed, 133 insertions(+)
create mode 100755 1-basics.rb
The output showed that there was 1 file change and 133 insertion (additions to the file).
Now if we check the status again, we’ll see this:
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
2-expressions_and_operators.rb
3-objects_and_classes.rb
4-inheritance.rb
5-modules_and_mixins.rb
README.md
nothing added to commit but untracked files present (use "git add" to track)
Let’s add the remaining files but this time in bulk using git-add
and the dot syntax to include everything in the current working directory.
$ git add .
Checking the status again will show all of the previously untracked files ready for a commit:
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: .gitignore
new file: 2-expressions_and_operators.rb
new file: 3-objects_and_classes.rb
new file: 4-inheritance.rb
new file: 5-modules_and_mixins.rb
new file: README.md
And now we can commit those staged files.
$ git commit -m "adding remaining files to repository."
[master 10183ab] adding remaining files to repository
6 files changed, 251 insertions(+)
create mode 100755 .gitignore
create mode 100755 2-expressions_and_operators.rb
create mode 100755 3-objects_and_classes.rb
create mode 100755 4-inheritance.rb
create mode 100755 5-modules_and_mixins.rb
create mode 100755 README.md
And running git-status
again shows that there are no more untracked files and our working directory is clean.
$ git status
On branch master
nothing to commit, working directory clean
That’s the basics of working with files in Git. If we didn’t have a set of files already, we could have also initialized an empty repository (also using git-init
) and then added files in as we created them.