Tuesday, October 1, 2013

Git notes

Create a new git from remote
make project_dir
cd project_dir
git remote add origin remote-project-path
git pull origin master
Set local upstream to remote branch
git branch --set-upstream master origin/master
Merge without adding "merge branch ... " message to log
git pull --rebase origin master
Merge without modifying log
git add .
git commit -m 'push to stash'
git pull --rebase origin master
(fix rebase conflict)
git reset HEAD~1
Rewind file state to last commit (changes are discarded, dangerous)
git checkout -- file-to-rewind
Unstate file changes and keep changes
git reset HEAD file-to-unstage
Undo last N commits
git reset --soft HEAD~N # keep changes
git reset --hard HEAD~N # discard changes (dangerous)
Modify the commit log.  See here for details.
git rebase --interactive hash-of-the-parent-commit
git push --force  # may cause issues if remote changes are pulled
Generate a changelog from git log
# list representation
git log --no-merges --pretty=format:' - %s'

# graphical representation
git log --graph --pretty=format:'%s - %Cred%h%Creset  %Cgreen(%cr)%Creset %an' --abbrev-commit --date=relative
Maintain a sub-repository using the subtree merging strategy: see this script.
usage: ./subtree ACTION (ARGS...)
 Actions  Arguments
 -------  -----------------------------------------------
  init    (root_git)
  create  subtree-name subtree-dir subtree-git (subtree-branch)
  update  subtree-name subtree-dir
  push    subtree-name
Create a new branch with clean history
git checkout --orphan new-branch
git rm -rf .
Force pull and overwrite local files:
git fetch --all
git reset --hard origin/master
git pull origin master

Resources

http://blog.wu-boy.com/tag/git/
A successful Git branching model

No comments:

Post a Comment