git push
Git can search diffs with the -S option (it’s called pickaxe in the docs)
git log -Spassword # word like –grep=word git log -Gword # regex
This will find any commit that added or removed the string password. Here a few options:
-p: will show the diffs. If you provide a file (-p file), it will generate a patch for you.
-G: looks for differences whose added or removed line matches the given regexp, as opposed to -S, which "looks for differences that introduce or remove an instance of string".
--all: searches over all branches and tags; alternatively, use --branches[=<pattern>] or --tags[=<pattern>]
git push
git commit –amend –no-edit # Amend without changing message
git diff –cached (stage vs currznt dir)
git diff –staged (stage vs commit)
git config –list
Add wisely
git cherrypick <commit_sha1>
git add -p # add by chunk (remember patch)
Store credentials
git config --global credential.helper cache
: Tells Git to keep your password cached in memory for (by default) 15 minutes. You can set a longer timeout with:git config credential.helper store
: Stores permanentlySubmodules
git submodule update --recursive --remote --jobs 8
git submodule sync
# after modyfing .gitmodulesgit pull --recurse-submodules
git submodule forech [--recursive] 'git reset --hard'
Merge commit
git reset --soft "HEAD~10"
# Merge last 10 commits into 1Display
git log --all --full-history -- **/thefile.*
git log --diff-filter=D --summary | grep delete
git log --all --{file_path}
: file_path can have * insidegit log --pretty=format:"%h"
git log --pretty=oneline
git log -S watever [--source --all] [--decorate] [--reverse]
: pickaxe or pickacegit log -G "^(\s)*function foo[(][)](\s.html)**{$"
: regexgit reflog
git show <COMMIT_ID> -- <FILE_PATH>
: show deleted filesgit checkout <SHA>^ -- <FILE_PATH>
git check-ignore *
: show ignored filesgit ls-files --others --exclude=standard
git ls-tree --full-tree -r HEAD
git cat-file -s
git diff-tree
Interface
git add -i
: add items without copying full file namePatch
git .git/objects/pack SAMPLE
git unpack-object < SAMPLE/*.pack
Ignore
.git/info/exclude
: personal gitignoreClean
git clean -[xd]n
: Show what I will cleangit clean -[xd]f
: DoGrep regex
git log -S'regex'
git log -S'regex'
git grep "regex"
Compress
git reflog expire --expire=now --all
git gc [--agressive --prune=now]
: garbage collectorFilter : remove certain files
git filter-branch --tree-filter 'rm -f pass.txt' ~HEAD
Clone only last commit
git clone --depth=1 http://www.github.com/toto/project.git
Disable security check (https)
git -c http.sslVerify=false origin master
Unstage all
git reset HEAD
Stop tracking
git rm --cached file
Ignore Windows newline
git config --global core.autocrlf true
Show word regex in diff
git diff --word-diff-regex=.
Get statistic lines changed stats
git diff --stat
Make backup
git stash && git stash apply
Aliasing
git config --global alias.wdiff diff --color-words
Edit ~/.gitconfig
[alias]
wdiff = diff --color-words
Word by word diff
git diff --color-words
Checkout all the files
git checkout -- .
Choose ours (master) theirs (current branch) automaticcaly in case of conflict
git rebase -Xtheirs branch-b
git merge -Xours origin/master
git checkout --ours foo/bar.java
git add foo/bar.java
Merge unrelated history (to merge different project)
–allow-unrelated-histories
Ignore file mode (755 in chmod)
git config core.fileMode false
Aliasing
git config –global alias.wdiff diff –color-words// Edit
~/.gitconfig` [alias] wdiff = diff –color-words
Word by word diff git diff –color-words
git config --local -e
[core]
... (existing configurations)
excludesfile = ~/Documents/my_repo/.local_gitignore
[remote "origin"]
... (existing configurations)
[branch "master"]
... (existing configurations)
git log --all -- <filepath accepting *>
git log --all --full-history -- **/thefile.*
git filter-branch --index-filter "git rm --cached --ignore-unmach file.txt" [HEAD~5..HEAD
# file?txt can have a *git rebase -i <commit>~1
# Can edit or delete commitsgit commit --amend --author="tinwin <tin@windows>
git init
git add LICENSE.txt
git commit -m 'first commit'
git clone https://github.com/libgit2 mylibgit
git config --global user.name "Martin T"
git config --global user.email tbf@tbf
core.editor vim
git config --list # See all config vars
git config user.name # See the var git is using for name
git config --global alias.co checkout
git config --global alias.br branch
git config --global alias.ci commit
git config --global alias.st status
git config --global alias.unstage 'reset HEAD --'
git config --global alias.last 'log -1 HEAD'
-> Each Commit has a pointer to the previous commit -> The default branch name is master git-master . -> HEAD is a pointer pointing to the current branch
git branch testing
< Creates a new pointer at the same commit you're currently on
git checkout testing git checkout -b testing # creates the branch and go in it < Moves HEAD to the testing branch
-> Switching to a branch changes the working directory
git branch
git branch -v # see the last commit
git branch -m <oldname> <newname>
< rename a branch
git branch [–no-merged] [–merged] < Lists all Branches
git log --oneline --decorate --graph --all
< Shows where branch pointers are
-> Creating a branch is just creating a 41 byte pointer (to a sha-1) in a file
# 5. Merge
-> You want to merge myBranch into master
git checkout master git merge myBranch < If you changed the same part of the same file differently, this will cause confict. So this won’t auto-merge and you have to resolve the conflict and then commit.
git status
< To see the conflict
Open the files manually to resolve the conflict and add them to the stage to remove them from conclicting files
git mergetool
git branch -d myBranch < To deleta a branch, usefull if this branch is already merged
-> Get the change one branch applied to the most common ancestor and apply this change to the other branch
git rebase --onto master server client
< Check client branch, figure the changes from the common
ancestor with client and apply these changes to master
git rebase master server git checkout master git merge server git branch -d server < Replay server changes on master branch Then go to the master branch (without the server applyed) And merge both branch so master and server are now one branch Remove the server branch, not usefull anymore
-> Don’t rebase commits that exist outside your repository
git remote add maisonDir D:\Iso\VimMaison
git ls-remote (remote)
git remote show (remote)
< To see all remote vars
-> Origin is the default name for a remote when you run git clone *git-origin*
git fetch origin < Fetch data from origin into a new branch called origin/master
git push (remote) (branch)
< Take my local branch and update the remote origin branch (with the same name)
git checkout -b serverfix origin/serverfix < This gives a local branch where origin/serverfix was
-> Tracking branches are local branches that are looking to remote branches. When you git clone, your master branch is tracking origin/master. You can then update master with “git pull”. From a tracking branch, git pull will act as git fetch and git merge
git remote add local_proc /opt/git/projct.git
git pull /home/john/project