Skip to content

Latest commit

 

History

History
executable file
·
538 lines (403 loc) · 17.4 KB

git-notes.txt

File metadata and controls

executable file
·
538 lines (403 loc) · 17.4 KB

-*- mode: org; comment-column: 0; -*-

Basics: Adding a remote to git repo

$ git init

$ git add .

$ git commit -m

$ git remote add origin [email protected]:vedang/reponame.git

Branching

$ git checkout -b <branchname> <commit>

$ git checkout -d <branchname>

$ git checkout -m <branchname> <newbranchname>

$ git merge <branchname>

$ git push <remotename> <localbranchname>:<remotebranchname>

$ git push <remotename> :<branchname>

$ git symbolic-ref HEAD refs/heads/newbranch $ rm .git/index $ git clean -fdx

$ git checkout –orphan newbranch $ git rm -rf .

$ git filter-branch –subdirectory-filter trunk HEAD $ git remote add trunk /path/to/trunk $ git push trunk master

$ git checkout masters_original_HEAD $ git checkout -b tmp $ git merge -s ours master $ git checkout master $ git merge tmp $ git reset –soft HEAD^

$ git checkout <branch_name> $ git branch –set-upstream-to=origin/<branch_name>

Merging and Rebasing

$ git merge -s ours <branchname>

$ git checkout develop $ git merge -s ours master $ git checkout master $ git merge develop

[~/testing (develop *+|MERGING u+7)] $ git status

#

#

#

#

#

$ git checkout –ours README.txt $ git add README.txt $ git commit

$ git remote add -f projA /path/to/projA $ git merge -s ours –no-commit projA/master $ git read-tree –prefix=subdirA/ -u projA/master $ git commit -m “merging projA into subdirA”

$ git rebase -p <branchname>

$ git merge-base <branch1> <branch2>

#

$ git revert M -m 2

Tagging

$ git tag -u <key-id> <tagname> <commitid>

$ git push <remotename> <tagname>

$ git push <remotename> <branchname> –tags

$ git tag -s <tagname> <commitid>

$ git fetch –tags origin

$ git tag -l

$ git tag –list –sort=version:refname

$ git tag -a

$ git describe –match v*

$ git describe –tags `git rev-list –tags –max-count=1`

$ git show v2.5:fs/locks.c

$ git rev-parse name

$ git tag -d 12345

$ git push origin :refs/tags/12345

$ git tag –contains <SHA>

Listing and Display

$ git diff –name-only rev1 rev2

$ git show –pretty=”format:” –name-only <commitid>

$ git log –pretty=oneline

$ git log –author=foo

$ git log –pretty=format:’%C(bold red)%h%Creset -%C(bold yellow)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)[%an]%Creset’ –graph

$ git log –author=$USER –format=”- %B” –since=-7days –reverse

$ git diff –name-status master..branch

$ git log -p <filename>

$ git shortlog master..branch

$ git log –branches –not –remotes

$ git log –pretty=format:’%C(bold red)%h%Creset -%C(bold yellow)%d%Creset %s %C(bold green)(%cr)%Creset %C(bold blue)[%an]%Creset’ –graph

$ git log –branches –not –remotes –simplify-by-decoration –decorate –oneline

$ git log @{u}..

$ git diff origin/master..HEAD

$ git diff rev1:filename rev2:filename

Patches

$ git diff [commit-id-before] [commit-id-after] > my.patch

$ git format-patch -3

$ git format-patch -k -s –stdout R1..R2 | git am -3 -k

$ git cherry-pick R1..R2

git format-patch master –stdout > diff-with-master.patch

$ git apply –stat diff-with-master.patch

$ git apply –check diff-with-master.patch

$ git am -3 –signoff < diff-with-master.patch

Submodules

$ git submodule add path_to_git_repo local_dir $ git submodule init $ git submodule update

$ git clone –recursive <path-to-remote-repo>

$ git rm –cached path_to_submodule # (no trailing slash)

$ git pull –recurse-submodules #requires git 1.7.3+

$ git submodule update –recursive

Subtree (1.7.11+)

$ git subtree split –prefix=subdir/ –annotate=’(split)’ -b split_dir $ git push [email protected]:yourname/your-repo.git split_dir:master

$ git subtree add –prefix=path/in/curr/repo –squash \ git://github.com/yourname/your-repo.git master

$ git subtree pull –prefix=path/in/curr/repo –squash \ git://github.com/yourname/your-repo.git master

$ git subtree split –prefix=subdir/ –annotate=’(split)’ -b split_dir_latest

$ git push [email protected]:yourname/your-repo.git split_dir_latest:master

Adding, Removing & Committing

$ git add -p

$ git cherry-pick <commit-id>

$ git commit –amend

$ git commit –amend -C HEAD

$ git clean -dxf <path>

Debugging, Recovery & Undoing

$ git bisect start $ git bisect good v2.6.18 $ git bisect bad master

$ git bisect good # or $ git bisect bad

$ git bisect reset

$ git bisect run my_script

$ git fsck –lost-found –no-reflog

git reflog

$ gitk v1.5.0.. <filenames/directorynames>

$ gitk –since=”2 weeks ago” – <filename>

$ gitk –max-count=100 –all – <filename>

$ gitk –all $( git fsck –no-reflog | awk ’dangling commit {print $3}’ )

$ git reset –soft HEAD@{1}

$ git commit -C HEAD@{1}

$ git reset –soft HEAD^1

$ git stash

$ git pull origin <branchname>

$ git stash pop

$ git log -g # Walks reflog and shows you a history of your actions

$ git reflog show –no-abbrev <branch name>

$ git checkout -m <file>

Misc

$ git apply –whitespace=fix

$ git filter-branch –commit-filter ’ if [ “$GIT_AUTHOR_EMAIL” = “original_email_address” ]; then GIT_AUTHOR_NAME=”FirstName LastName”; GIT_AUTHOR_EMAIL=”new_email_address”; git commit-tree “$@”; else git commit-tree “$@”; fi’ HEAD

$ git commit –amend –reset-author

$ git daemon –reuseaddr –verbose –base-path=. –export-all ./.git

$ git config –global alias.serve ‘!git daemon –reuseaddr –verbose –base-path=. –export-all ./.git’

$ git clone git://192.168.254.135/ project

Extra configuration for a better Git experience

$ git config –global user.name “FirstName LastName”

$ git config –global user.email “[email protected]

$ git config –global color.ui “auto”

$ git config –global rerere.enabled 1

$ git config –global branch.autosetuprebase always

$ git config branch.*branch-name*.rebase true

$ git config –global branch.autosetupmerge always

$ git config –global merge.summary true

$ git config –global user.signingkey <keyid>

$ git config –list