Random Git Stuff

While going through the iOS tutorial, I picked up a few tips on git, some of which might be obvious to some veterans. Either way I’d like to share what I learned.

Git Log

Using “git log” I can get a list of all commits. If necessary, I can revert to any one of my commits even if I did not already create a branch. Some sample output might look something like this:


tab-mpenzone:elearning-plugin DanMiller$ git log
commit 25e08b1751992a9c18bd3ed7aba34310a8b74ddf
Author: Dan Miller <DanMiller@lap-kleblanc1.cynosurelaser.com>
Date: Fri Nov 13 17:02:07 2015 -0500

refactored some code

commit 161efd888cdff469c9615e67506c8e5d2a3a87c9
Author: Dan Miller <DanMiller@adminisatorsmbp.cynosurelaser.com>
Date: Thu Oct 1 17:29:00 2015 -0400

many changes

commit 8710fcd6e599a8dcb2d1eeeceaf20799cc4f269f
Author: Daniel Miller <dmiller@cynosure.com>
Date: Wed Aug 26 18:06:39 2015 -0400

stuff

commit bdc87017416b170eb0aa73a8185f8eca7b338bdd
Author: Daniel Miller <dmiller@cynosure.com>
Date: Tue Aug 25 17:51:23 2015 -0400

another commit

commit f40ea507f7bc532381f51a377980045f7f89bc2b
Author: Daniel Miller <dmiller@cynosure.com>
Date: Mon Aug 24 17:39:04 2015 -0400

added new classes

commit 70d426413de9570d00894af88c819ae95978227e
Author: Daniel Miller <dmiller@cynosure.com>
Date: Thu Aug 20 17:36:33 2015 -0400

latest changes

commit 0274bc4b213b899951efa84b5b8730f73ac14ea4
Author: Daniel Miller <dmiller@cynosure.com>
Date: Tue Aug 18 17:28:37 2015 -0400

added json api

commit d934ef568b343fd55643b86a8959c4b16d79a36f
Author: Daniel Miller <dmiller@cynosure.com>
Date: Mon Aug 17 17:32:58 2015 -0400

organized code

commit 9b55b02aa1b3587081daeb5567b5799d22026289
Author: Daniel Miller <dmiller@cynosure.com>
Date: Fri Aug 14 17:03:47 2015 -0400

working on validations

commit d6ca533d59d49d98b4d3c52cda00972e2de5678a
Author: Daniel Miller <dmiller@cynosure.com>
Date: Tue Aug 11 17:41:19 2015 -0400

second commit

commit b1e7926f621d8074f6212b39a8f24f8fd6ba3831
Author: Daniel Miller <dmiller@cynosure.com>
Date: Mon Aug 10 17:28:25 2015 -0400

first commit

 

Obviously this guy is not committing often enough…

You can actually revert to any of these items in the log by using the first 7 character of the commit number. For example if I wanted to go back to the first commit I could type:

git checkout -b b1e7926

This is pretty useful if you did not create a named branch, but want to go back to a certain date.

Another thing that was new to me is using “-A” to add all files. I normally used the command:

git add .

I actually assumed this was adding all files, but that was an incorrect assumption. The “.” only adds all files that are new or have been changed. Using “-A” is where you actually add everything.

I can also delete a branch. I am not sure its something that I would ever do, but its handy to know about. This can be done with:

git branch -D branchname

None of this is groundbreaking stuff by any means, but it is new to me and I figured I’d share it to the world. Maybe it will help somebody out there.

Leave a Reply

Your email address will not be published. Required fields are marked *