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 com­mit, we have to add it and then com­mit it. This is dif­fer­ent than what you’re use to using Subversion.

The long­hand ver­sion 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 com­mand using the -a switch to first add the file and then bun­dle it up into a com­mit. This will work for one or more mod­i­fied 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