Difference between revisions of "Git"

From YobiWiki
Jump to navigation Jump to search
Line 25: Line 25:
 
git commit -a
 
git commit -a
 
File renaming is implicit, so you don't have to take care, just rename your files if you want
 
File renaming is implicit, so you don't have to take care, just rename your files if you want
  +
  +
Diff between working files & repository
  +
git diff
  +
With specific revision or path
  +
git diff <rev> <path>
  +
E.g with one but last commit
  +
git diff HEAD~1
  +
This provides usage patches, including metadata, can be applied with
  +
git apply
  +
Status of local working files
  +
git status
  +
 
==Initial project==
 
==Initial project==
 
Add manually files/directories e.g. with
 
Add manually files/directories e.g. with

Revision as of 22:39, 16 September 2008

Links

Install

sudo apt-get install git-svn git-doc git-gui tig

Writing to global ~/.gitconfig file:

git config --global user.name "Your Name Comes Here"
git config --global user.email you@yourdomain.example.com
git config --global color.diff auto
git config --global color.status auto
git config --global color.branch auto

Creating a .git in the current (project) directory:

git init

Basic usage

Schedule a file for committing

git add <file>

Committing

git commit

Note that a modified file must be explicitly added every time, unless you use

git commit -a

File renaming is implicit, so you don't have to take care, just rename your files if you want

Diff between working files & repository

git diff

With specific revision or path

git diff <rev> <path>

E.g with one but last commit

git diff HEAD~1

This provides usage patches, including metadata, can be applied with

git apply

Status of local working files

git status

Initial project

Add manually files/directories e.g. with

git init
git add .
git commit

Copying existing project

Clone an existing Git repository into a to-be-created target directory:

git clone /path/to/other/repository target

Remote repositories can also be accessed with paths like

ssh://login@host/path/to/repository
git://git.software.org/trunk
http://git.software.org/trunk

Later to update the local repository according to the remote repository:

git pull

Symmetrically the remote repository owner could also get the changes we've done locally if she does:

git pull /path/to/our/target

Or we could send them ourselves if we've write access on the remote:

git push

BTW the remote can create a shortcut to us to not have to provide our full path everytime

git remote add ourshortcut /path/to/our/target

And now use directly

git remote show ourshortcut
git pull ourshortcut

Note that git pull ourshortcut ==

git fetch ourshortcut
git merge ourshortcut/master

Using a Subversion server

Getting the full project:

# git clone =>
git-svn clone http://subversion.server.com/project -T trunk -b branches -t tags
(git-gc to compress if it took a big room)

Updating the local repository according to the subversion server:

# git pull =>
git-svn rebase

Sending the local changes to the subversion server:

# git push =>
git-svn dcommit

Ignoring some files

cat > .gitignore <<EOF
*.pyc
*~
EOF
git add .gitignore

Misc

  • Revisions are SHA-1 hashes, not incremental numbers.
    You can refer to the latest revision by HEAD, its parent as HEAD^ and its parent as HEAD^^ = HEAD~2
    You can also just type the first digits of the hash (if it's enough to get a unique ID)
    man git-rev-parse for more details
  • The Git commands are in the form git command. You can interchangeably use the git-command form as well.

etckeeper

TODO