Gavin Flood

Ramblings of an Irish software developer

Resolving Git Issues With Git

I use Git as my VCS of choice. It's easy to get started with, well documented and has a good community around it. I could spend all day listing off things I like about it. I have experience with Subversion and even Perforce, but I've always felt like Git made the most sense in the decisions it made. To put it simply, Git is awesome!

Anyway, here's some crappy situations I've gotten myself into with Git and how I managed to resolve them.

I forgot to include a file in a commit

git add some_file
git commit --amend

You committed a bunch of changes and forgot to include something. You don't want to have a new commit just for this small addition. Use the commands above and follow the prompts to include the forgotten files in the commit.

I want to discard some local modifications

git checkout -- some_modified_file

You made a change to a file locally and now want to disregard that change. It's a common thing to happen. You will get used to using the above command.

Remove a file from Git

git reset some_file

You want to remove a file from Git but not delete it from your file system. Use the command above to do so. Then think about adding the file to your .gitignore.