Difference between revisions of "Git Notes"

(Explain something about commit ranges (requested by Dr Bene))
m
Line 8: Line 8:
  
 
;<source lang="bash">git branch -m <new branch name></source>
 
;<source lang="bash">git branch -m <new branch name></source>
;Rename the current branch.
+
:Rename the current branch.
  
 
;<source lang="bash">git reset --hard HEAD^</source>
 
;<source lang="bash">git reset --hard HEAD^</source>

Revision as of 10:50, 17 December 2009

Some things that I wouldn't remember otherwise

git init --shared=group
Tell the repository that it should always set the permissions to g+w.
git init --bare --shared=group
Idem, but a bare repository (that is, no files checked out, so you can push to it.) This is meant for a remote server repository that all your coworkers push into and pull/fetch from.
git branch -m <new branch name>
Rename the current branch.
git reset --hard HEAD^
Roll back.
git reset --hard HEAD@{1}
Roll back.
git checkout HEAD@{1} -- <file>
Cherry pick one file revision from the previous commit.
git diff <branch1> <branch2> -- <file>
Diff a file between two branches.
git log -p --color-words
Display a log with colored word diffs. Say "-S" to less to virtually wrap long lines.
git diff <commit a>:<file> <commit b>:<file> --color-words
Display a diff with colored words between a file in one commit and a file in another commit. Say "-S" to less to virtually wrap long lines.

Tutorials

How to create a shared remote repository?

ssh you@server
mkdir repos/remote.git
cd repos/remote.git
git --bare init --shared=group
logout

cd ~/local
git remote add origin ssh://you@server/home/you/remote.git
git push origin master
git config branch.master.remote origin
git config branch.master.merge refs/heads/master

Creates a bare remote repository at ssh://server/home/you/remote.git that tracks your local repository in /home/you/local. Adopted from [Tim Lucas].

How to display a filtered set of commits?

Assume you want to see commits in branch stephan, but only those that are not part of the history of branch saalfeld:

git log stephan ^saalfeld

More realistically, if you want to see all the commits which are in a topic branch, but not yet merged into master:

git log --all ^master

If you want to see the changes which come from a topic branch which was merged in commit deadbeef, use this command line:

git log deadbeef^..deadbeef^2

Explanation: deadbeef is a merge commit, so its first parent (deadbeef^, can also be written as deadbeef^1) was the current HEAD when the merge was performed, and the second parent (deadbeef^2) is the tip of the branch which was merged. The argument A..B is short form of ^A B, i.e. all commits reachable from B excluding those which are also reachable from A.