Last active
August 29, 2015 14:00
-
-
Save nfet/11013504 to your computer and use it in GitHub Desktop.
Git Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add Git Notes Here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[alias] | |
diff-last = diff HEAD^1 | |
lg1 = log --graph --abbrev-commit --decorate --date=relative --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all | |
lg2 = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all | |
lg = !"git lg1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Create New Local Repository | |
%> mkdir [new-project] | |
%> cd [new-project] | |
%> git --bare init | |
Initially Push to Remote | |
%> git remote add origin [url] | |
%> git push -u origin master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Log with graph | |
%> git log --graph | |
# Log remote | |
%> git log origin/master | |
%> git log origin/[branch] | |
# Diff Against Remote Origin | |
%> git diff --stat origin/master | |
# Diff Against a Remote Branch | |
%> git branch -a | |
%> git diff --stat origin/[branch]..origin/master | |
OR | |
%> git diff --stat remotes/origin/[branch]..origin/master |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add Origin | |
%> git remote add origin | |
# Add Upstream | |
%> git remote add upstream [url] | |
# Show Remotes | |
%> git remote show | |
# Show Remote Origin/Upstream | |
%> git remote show origin | |
%> git remote show upstream | |
# Change Origin | |
%> git remote set-url origin <new-url> | |
%> git remote show origin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create Branch & Checkout | |
%> git checkout -b [mybranch] | |
# Push Branch to remote for the first time | |
%> git push -u origin [mybranch] | |
# Push a local branch to a remote branch | |
%> git push origin [localbranch]:[new_remote_branch] | |
# Delete a remote branch | |
%> git push origin :[branch_to_delete] | |
# Checkout a remote branch | |
%> git fetch or git pull | |
%> git checkout -b [new_branch_name] origin/[branch_name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reset and still indexed (added) previous commits (keep commits) | |
%> git reset --soft //head | |
%> git reset --soft [hash] | |
# Reset and un-index previous commits (keep commits) | |
# Previous commits are rolled up | |
%> git reset --mixed // head | |
%> git reset --mixed [hash] | |
# Reset and delete previous commits (HEAD) | |
%> git reset --hard // head | |
%> git reset --hard <hash> | |
# Revert previous commit (in master) | |
%> git fetch or git pull | |
%> git reset --soft HEAD^ //resets to previous commit | |
%> git push origin master --force | |
# Revert to a hash (in master) | |
%> git fetch or git pull | |
%> git reset --soft <hash> | |
%> git push origin master --force | |
# Roll up previous commits (in branch) | |
%> git fetch or git pull | |
%> git reset --mixed <hash> | |
%> git add -A && git commit -m "rolled up into one" | |
%> git push origin [branch_name] --force | |
SEE ALSO: | |
http://makandracards.com/makandra/527-squash-several-git-commits-into-a-single-commit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment