Adding Modified Files in Git
Let’s go in to our files and make a change. Open up the file 1-basics.rb
and add a cities
array around line 54.
cities = ["Houston", "Austin", "Dallas"]
If we check git-status
that file should come up as modified.
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: 1-basics.rb
no changes added to commit (use "git add" and/or "git commit -a")
To include this file in a commit, we have to add it and then commit it. This is different than what you’re use to using Subversion.
The longhand version is this:
$ git add 1-basics.rb
$ git commit -m "added a new array with Texas cities"
[master c559074] added a new array with Texas cities
1 file changed, 2 insertions(+)
But we can also do it in one command using the -a
switch to first add the file and then bundle it up into a commit. This will work for one or more modified files.
$ git commit -a -m "added a new array with Texas cities"
[master c559074] added a new array with Texas cities
1 file changed, 2 insertions(+)
Now if we look at our log again we’ll see our new commit:
$ git log
[master c559074] added a new array with Texas cities
1 file changed, 2 insertions(+)
commit c559074e30268216d09c1eacbd6658dec7ebc94c
Author: Ryan Irelan <[email protected]>
Date: Fri Apr 1 12:07:33 2016 -0500
added a new array with Texas cities
commit 10183ab59acbea83c8aed6cde90d5b2e8506191f
Author: Ryan Irelan <[email protected]>
Date: Fri Apr 1 11:50:16 2016 -0500
adding remaining files to repository
commit 0542a0f470d5e5e4af0bb2a7573ab9fc34167475
Author: Ryan Irelan <[email protected]>
Date: Fri Apr 1 11:13:40 2016 -0500
adding first file