git commands - dmwm/WMCore GitHub Wiki

git tutorial: (Pro Git from Scott Chacon) Pro Git

  • initializing a repository in an existing dirrectory
git init    -- creates a new sub directory .git and structure for git. (but nothing is tracked)
git add *.py
git commit
  • Cloning an existing repository
git clone git://github.com/dmwm/WMCore.git
  • git commend to find the status
git status
git diff (changed but not staged)
git diff --staged (or --cached) (staged but not yet committed)
git commit (only commits staged files) 
    options
    -a (commit all the tracked file add + commit)
    -v (for diff changes on comments)
  • Removing files
rm filename
git rm filename
     -f (forced removal already in index)
git rm --cached (remove only from staged area - physical file exist)

  • Moving files
git mv file_a file_b
  • Viewing log
git log -p -2 (p shows the diff, 2 limits the last two commit)

git log
git log --stat
git log --pretty=oneline  (short, full, fuller)
git log --pretty=format:”%h -%an, %cn : %s” --graph 
      --since, --after, --until, --before, --author --commiter --no-merges
git log --graph --simplify-by-decoration --pretty=format:'%d' --all
  • Undoing things
git commit --amend (fix the previous commit - add files, change comment)
  • UnStage the file
git reset HEAD file_a
  • Un-modify the file (not reversible: use with the caution)
git checkout -- file_a  (remove the changes)
  • Working with remote.
git remote -v  (shows remote name and origin)
git fetch [remote-name]
git push [remote-name] [branch-name]
git remote show [remote-name] detail inform from remote
git remote add [pb] [git://.....]
git remote rename [pb] [paul]
git remote rm [paul]
git checkout -t [remote-name/branchname] tracking remote branch with the same name of local branch
git chekout -b [different name] [remote-name/branchname]
  • Tagging
git tag - (list the tag)
git tag -l v1* (select the tags)
  • creating tags
  • Annotated tags
git tag -a v1.4 -m ‘my version 1.4’

  • temporary tag
git tag  v1.4.temp
  • signed tags (with your private key)
git tags -s v1.4
  • verifying signed tag (use public key in your key ring)
git tags -v v1.4
  • add additional commit to tag
git tag -a v1.2 [part of checksum]
  • sharing tags with remote
git push origin v1.4
  • remove tag
git tag -d v1.4
git push origin :refs/tags/v1.4
  • branching is the snap shot of the repository light way pointer to commit object

  • create branch

git branch branch_name
switch to branch
git checkout branch_name
  • combined
git checkout -b branch_name

merging branch : merge test to master

git checkout [master] git merge [test]

  • check the un/merged branch
git branch --merged
git branch --no-merged
  • deleting the branch
git branch -d branch_name (this won’t delete unmerged branch)
git branch -D branch_name (force delete)
  • compare branches
git diff --name-status master..branch
git diff master..branch
git log master..branch
git shortlog master..branch
  • create patch and apply
git format-patch master --stdout > fix_empty_poster.patch
git apply --stat fix_empty_poster.patch
git apply --check fix_empty_poster.patch
git am --signoff < fix_empty_poster.patch