Although there are enough resources on the web about Git, I will keep this one for my own reference. Minimal Git version required 1.7.2.
- index: staging area (Imagine you are loading sand into the truck with bucket. Well, the bucket is like index and truck like a repository :)
- <sha1>: sha1 hash of commit
- <file>: path to the file (path/to/file.ext)
- <branch>: branch name
- <repository>: remote repository name
git log --diff-filter=D --summary
git checkout <sha1>^ <file>
git show <sha1>^:<file>
git diff -M <branch>
git log -p <file>
git cherry <upstream_branch> <new_branch>
git log <upstream_branch>..<new_branch>
git log --name-only
git log --name-status
git log --stat
git describe --exact-match --abbrev=0
git describe --abbrev=0 --tags
git add --patch <file>
- y: stage this chunk
- n: do not stage this chunk
- s: split this chunk into smaller chunks
- e: edit this chunk
If not provided, Git uses HEAD
as the new branch start point.
git checkout -b <branch>
git checkout -b <branch> <start>
or
git branch <branch>
git checkout <branch>
git branch <branch> <start>
git checkout <branch> <start>
Delete already merged branch
git branch -d <branch>
Force branch deletion
git branch -D <branch>
Pick from start <sha1>
commit till end <sha1>
commit.
git cherry-pick <sha1>..<sha1>
Create combined patch containing all commits from the current branch against to a branch.
git format-patch <branch> --stdout > <patch>.patch
Check what changes are in the patch
git apply --stat <patch>.patch
Test the patch before applying
git apply --check <patch>.patch
Apply patch
git am [--signoff] < <patch>.patch
Check out git reset for great explanation and examples.
git reset --hard
Check out git reset for great explanation and examples.
git reset --merge ORIG_HEAD
git revert <sha1>
git checkout <sha1>^ -- <file>
git checkout -b <branch> <repository>/<branch>
git branch --set-upstream <branch> <repository>/<branch>
git push <repository> :heads/<branch>
git push <repository> :<branch>
git push <repository> --delete <branch>
git remote prune <repository>
git remote set-url <repository> https://example.com/repo.git
git submodule foreach 'git checkout master && git pull origin master'
Edit the .gitmodules file, then run:
git submodule sync
- remove the submodule's entry in the .gitmodules file
- remove the submodule's entry in the .git/config
- run
git rm –cached path/to/module
- without a trailing slash! - remove the submodule from the filesystem, run
rm -rf path/to/module/
- commit changes