|Version 12 (modified by dukeleto, 6 years ago)|
Before you do anything, you should probably install the bash completion script for git, it makes the learning curve a lot less steep: http://repo.or.cz/w/git.git?a=blob;f=contrib/completion/git-completion.bash
It will make your prompt be something really cool like:
~/git-svn/parrot parrotobj $
where parrotobj is the name of the branch. There are many other useful setting if you read the comments in git-completion.bash .
To check out a repo:
git clone git://github.com/leto/parrot.git
There should now be a directory called "parrot" in your current directory.
Next we modify a file so we can commit a change:
echo "Some junk" >> README
To see a list of modifies files:
should produce something like
# On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: README #
To commit all local changes:
git commit -a -m "I did some stuff"
If you had multiple changed files that you wanted to commit seperately, you would do
git add README git commit -m "I commit stuff"
LESSON: Git only commits files you have added already. The -a flag lets you be lazy and say "go ahead and add all modified files" when you are commiting.
git log -10 to see the commit message and metadata for the last 10 commits.
git log -p to see the commit history as a series of patches .
You can give git log a file name or directory or a branch name. Very useful!
The equivalent of "svn up" is
To see a list of current local branches:
To see all local and remote branches:
git branch -a
create a branch
Suppose you want to create a local branch to work on your latest and greatest new feature. To create a new branch and check it out all in one automagical command:
git checkout -b new_branch
If you want to create the branch and check it out seperately (maybe because you want to do something else in between or batch the creation of many branches/etc..)
git branch some_branch
Later on, you can checkout some_branch with:
git checkout some_branch
Let's say you are on new_branch but you want to go back to the master branch:
git checkout master
To merge the foobar branch into the current branch:
git merge foobar
Git has everyone's favorite VCS command, blame!
git blame somefile
The equivalent of svn revert is roughly git checkout. Let's say we totally borked a file, README and we want to revert that file:
git checkout README
If you want to blow away all local changes, the equivalent of svn revert -R . is
git checkout .
Need more help? To get the man page for the git command foo type
git help foo
If you just want a short rundown of commandline options and such, try
git foo -h
OH NOES, git lost my work, I hate git, give me svn back
If you think you lost your committed work, you are probably wrong. Try
This command is your best friend. It records the tip of every commit, even if it is not part of any branch. Did you accidentally delete that really important branch ? Did you rebase away that really cool feature? Find the sha1 one that you want to go to and then type
git reset --hard sha1
If you want to keep track of that important sha1, you probably want to create a branch at that point:
git checkout -b this_branch_is_awesome
how do I get that thing over there on that onto this branch here?
Find the sha1, a single commit that you would like to "borrow" from another branch, or perhaps something you found in the reflog, then type:
git cherry-pick sha1
If you have multiple commits to pull over, then you must do multiple cherry-pick's.