Newbie's Git Cheatsheet
My team is switching our entire code base from perforce to git. And so far I gotta say git roks.
Here is my notes of some really simple and day-to-day commands:
Basic Commands
1 git status
2 git add (filename)
3 git commit
4 git diff --staged
5 git pull
6 git log --graph --all
Updating one file
1 git add (file)
2 git commit
3 git push
Integrating with remote
1 git pull
or
1 git fetch
2 git merge
revert a file that’s not committed
1 git reset HEAD -- (filename)
revert a file that’s commited
First figure out which version should it be reverted to:
1 git log --graph --all
Copy the sha1 from the desired history
1 git checkout (sha1) (filename)
Work on 2 branches at the same time
Find a point where you want to create branch:
1 git log --graph --all
Go to that point:
1 git checkout (sha1)
create 2 branches:
1 git branch b1
2 git branch b2
switch to one of them and work on it:
1 git checkout (branchname)
Merge branch back to mainline:
1 git checkout master
2 git merge b1
3 git merge b2
4 git commit
5 git push
blog comments powered by Disqus