git
Show files with assume-unchanged bit set:
git ls-files -v | grep "^[a-z]"
Show file from previous revision (treeish - branch or HEAD):
git show <treeish>:<file>
Squash first two commits
Suppose you have a history containing the three commits A, B and C:
A-B-C
I would like to combine the two commits A and B to one commit AB:
AB-C
Start rebase:
git rebase -i A
Continue with edit
rather than squash
:
edit e97a17b B
pick asd314f C
then run
git reset --soft HEAD^
git commit --amend
git rebase --continue
[ Source: http://stackoverflow.com/questions/435646/how-do-i-combine-the-first-two-commits-of-a-git-repository ]
Copy files preserving directory structure
cp --parents `git diff --name-only --staged` ~/directory
Read tree from different commit to index
git checkout master -- presentation/main
Recover files added to index but lost
This command will create .git/lost-found/other
directory with blobs that are not referenced anywhere:
git fsck --lost-found
Quick commands
git reset --soft HEAD~
- remove commit and move its contents into index,git reset --mixed HEAD~
- remove commit and move its contents into working directory,git status -uall
- show all untracked files,git clean -n
- check what would be removed ifgit clean -f
was used.
Show ten most frequently changed files
git log --pretty=format: --name-only | sort | uniq -c | sort -rg | head -10
Search for file names in repository
git ls-tree -r HEAD | grep GenericByte
Get old version of a file under new name
git show HEAD^:full/path/main.cpp > old_main.cpp
Log in tree format
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
Cannot allocate heap
c:\msysgit\bin>rebase.exe -b 0x50000000 msys-1.0.dll[ Source: http://jakob.engbloms.se/archives/1403 ]
Remove a directory from all commits
git filter-branch --index-filter 'git rm --cached -r --ignore-unmatch yeoman_app' --prune-empty --tag-name-filter cat -- --all