Wed 17 Feb 2010
Gitting better with Git
Posted by nola under git, open source
Comments Off
In the past few weeks I’ve been doing alot of Git and alot more collaboration with people on projects! So i wanted to point out some of the things i’ve learned and some handy tips I picked up.
I was aimee remotely and she showed me how to “stage” a commit. Which is a way to indicate “HEY this is going to be commited when you do git commit!” I used to always do commit -a which adds all the files not currently in the staging. I used perforce for awhile and learned how nice it was to have a “change list” and how you can commit only certain files at a time. Git seems like you can only have one “change list” at a time but that is fine in most cases.
git add -p
It will go through each changed file and ask if you want to stage this hunk. We were able to see what files we had changed as it showed a diff. You can confirm or deny chunk by chunk. today I like to run it to make sure I didn’t accidentally change a file. I have a habit of leaving a file open, walking away and coming back and adjusting the spacing. Probably not something I need to in a commit.
git status
This is really cool command, not only does it show you what is in staging it tells you what to do with the other files to either add/remove etc to get the commit in the shape you want. After working with git more, i went back and re-watched the peepcode screencast on git. I understand it better now!
After we committed, we realized we made a mistake in log message, so we did
git commit --amend
It will amend the last message in your git repo. I recently tried this with one of my commits, but I had already pushed to origin. I was kind of confused, so I asked aimee, she said
no If you have already pushed, you can git push –force to update, but be careful because it destroys references, so if there’s a chance someone else may have pulled the commit in the meantime you won’t want to go pulling the rug from under their feet, y’know!
![]()
Ahh, makes sense aimee!!
Another sticky point for me was — what is inverse of git add? git rm?I keep a git repo of code I am working on as I to learn stuff, practice etc. Most if it is probably not really worth browsing, but i like to point my friends there when I talk about what I am doing. I wanted to clean up some stuff that I don’t want to keep and mistakenly thought if I git rm it would remove it from the staging. Nope, it removes it! Well, to revert a file back to what you use this:
git checkout — file.txt
more on this Why is “git rm” not the inverse of “git add”?
Anyways, a few tidbits of information I’ve learned recently, hope this can help you git better at git
sources I found helpful
