Last active
August 22, 2017 18:33
-
-
Save gotofritz/f8a307cd6d20f12db6cb366e18bc148f to your computer and use it in GitHub Desktop.
Revisions
-
gotofritz renamed this gist
Aug 22, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
gotofritz revised this gist
Aug 22, 2017 . 13 changed files with 15 additions and 0 deletions.There are no files selected for viewing
File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.File renamed without changes.This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ # Bulk Resolve Conflics # Changing username after a commit # Compare Versions # Delete A Branch # Empty Dirs # Get Info # Ignore A File That Was Already Pushed # Log With Actual Changes # Log With List Of Files # Move Commits To Another Branch # Remove Added # Squash Commits # Sync # Undo A Commit # Which Branch Contains Commit -
gotofritz revised this gist
Jul 20, 2017 . 3 changed files with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,6 +13,9 @@ Author: that cowboy <[email protected]> # bonus points: you can also change the message (but don't have to) git commit --amend # push again git push -f > git log commit 174042a6944536e3908d76dc8ad51c8d354910f3 Author: John Wayne <[email protected]> File renamed without changes.File renamed without changes. -
gotofritz revised this gist
Jul 20, 2017 . 1 changed file with 20 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ # You have pushed some changes, do git log and then noticed that your username is all wrong > git log commit 174042a6944536e3908d76dc8ad51c8d354910f3 Author: that cowboy <[email protected]> blah blah # Open ~/.gitconfig - there should be a section for the username. If not, add one [user] name = John Wayne # change the commit # bonus points: you can also change the message (but don't have to) git commit --amend > git log commit 174042a6944536e3908d76dc8ad51c8d354910f3 Author: John Wayne <[email protected]> blah blah -
gotofritz revised this gist
Apr 24, 2017 . 2 changed files with 11 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,13 @@ git reflog # find the hash you are interested in git checkout -b aBranch <HASH> # undoes safely a PUSHED commit # what it actually does is create a commit which undoes commit hash git revert <HASH> # the same for a range of commits git revert <HASH BEFORE the first>..<last HASH> # nukes a PUSHED commit # there'll be mayhem if someone has pulled the commit being nuked git reset <HASH> git push -f This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,2 +1,2 @@ # list branches which contains a commit git branch --contains <commit> -
gotofritz revised this gist
Apr 19, 2017 . 1 changed file with 26 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ # syntax: # HEAD~ == HEAD^ == 1 commit back # HEAD~2 == HEAD^^ == 2 commits back # etc # rolls back a LOCAL commit leaving all files intact # after that you have to git add files again, then git commit git reset HEAD~ # rolls back a LOCAL commit leaving all files intact # after that you can do git commit immediately git reset --soft HEAD~ # rolls back a LOCAL commit and all traces of it git reset --hard HEAD~ # restoring a commit destroyed with git reset --hard git reflog # find the hash you are interested in git checkout -b aBranch <HASH> # undoes a PUSHED commit # note that HEAD is really HEAD^ # and HEAD^ is equal to HEAD^^ ... git reset HEAD -
gotofritz revised this gist
Apr 10, 2017 . 2 changed files with 5 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ # tells you name of current branch git rev-parse --abbrev-ref HEAD # tells you hash of last commit git rev-parse HEAD -
gotofritz revised this gist
Apr 10, 2017 . 2 changed files with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # tells you name of current branch git rev-parse --abbrev-ref HEAD This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,2 +0,0 @@ -
gotofritz revised this gist
Jan 30, 2017 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,8 @@ # delete a branch locally git branch -d BRANCH # force delete a branch locally git branch -D BRANCH # delete a branch remotely git push origin --delete BRANCH -
gotofritz revised this gist
Jan 13, 2017 . 1 changed file with 31 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ # You work on master, then after a while you realize you should have worked in a branch. # You want to move the last X commits to a branch and remove them from master # commit what you got, even if it doesn't work git commit -m "work in progress, doesn't work" -a # create the new branch - it will have everything master has git checkout -b MY_NEW_BRANCH # go back to master and remove the extra commits # be extra careful if other people have pushed / pulled git checkout master git reset --hard HASH_OF_COMMIT # or HEAD^ if you just want to undo the last commit # or HEAD~3 if you just want to undo the last 3 commits git push --force origin master # now carry on working on new branch git checkout MY_NEW_BRANCH # if you had commit things that did not work, uncommit, keeping the changes on your filesystem git reset HEAD^ # ...do work... # commit working files git commit -m "now it works" -a # push it to the remote git push origin MY_NEW_BRANCH -
gotofritz revised this gist
Dec 12, 2016 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,4 +10,14 @@ git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})" # the kosher way of doing previous example git rebase -i <sha-of-last-commit-BEFORE-the-ones-you-are-after> (this will open an editor window, where you have to manually change all the "pick" except the first one to "squash") # undo the undo - if you change your mind git reflog > 54439b8 HEAD@{0}: reset: moving to HEAD~1 > 6fd9bfa HEAD@{1}: commit: YOUR COMMIT MESSAGE > ... git reset HEAD@{1} # or git reset 6fd9bfa -
gotofritz revised this gist
Nov 18, 2016 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # all the commands below also work with difftool instead of diff # compares two commits of a file git diff <commit> <commit> <file> @@ -8,7 +10,7 @@ git diff -w <commit> <commit> <file> git diff HEAD^^ HEAD <file> # compares stae of all js files in <dir> with that three commits ago # note that often this doesn't work because the $(find..) returns # too long a string git diff HEAD HEAD^^^ -- $(find <dir> -name '*.js') -
gotofritz revised this gist
Nov 18, 2016 . 1 changed file with 16 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ # compares two commits of a file git diff <commit> <commit> <file> # compares two commits of a file and ignore whitespace git diff -w <commit> <commit> <file> # compares current state with two commits ago git diff HEAD^^ HEAD <file> # compares stae of all js files in <dir> with that three commits ago # note that often this doesn't work because find the $(..) returns # too long a string git diff HEAD HEAD^^^ -- $(find <dir> -name '*.js') # compares head with all commits since 01/01/16 git diff @{2016-01-01} <file> -
gotofritz revised this gist
Sep 26, 2016 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ # you can't have empty dirs in git. The best you can do is to have a .keep or .gitignore or README.md file in there -
gotofritz revised this gist
Sep 26, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # remove filename, a file already pushed, from git without deleting file git rm --cached filename # afterwards, add to .gitignore -
gotofritz revised this gist
Sep 6, 2016 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ # removes files added to git by mistake but not pushed, for example node_modules/ git rm --cached debug.log git rm --cached -r node_modules -
gotofritz revised this gist
Aug 5, 2016 . No changes.There are no files selected for viewing
-
gotofritz revised this gist
Jul 22, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ # from http://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git#5189600 # undo last X commits, and commit with a new message as one git reset --soft HEAD~X git commit -a -m "COMMIT MESSAGE" -
gotofritz revised this gist
Jul 22, 2016 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ # undo last X commits, and commit with a new message as one git reset --soft HEAD~X git commit -a -m "COMMIT MESSAGE" # undo last X commits, and commit with old messages git reset --soft HEAD~X git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})" # the kosher way of doing previous example git rebase -i <sha-of-last-commit-BEFORE-the-ones-you-are-after> (this will open an editor window, where you have to manually change all the "pick" except the first one to "squash") -
gotofritz revised this gist
Jun 20, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # after your pull creates a lot of conflincts, if you just want to accept other devs' changes grep -lr '<<<<<<<' . | xargs git checkout --theirs -
gotofritz revised this gist
May 23, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # list branches which contains a commit git branch --contains <commit> -
gotofritz revised this gist
May 23, 2016 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ # finds what files where changed in a specific commit # --stat: list of files # --pretty=oneline: makes output terse # -n 1: just the one commit git log --stat --pretty=oneline -n 1[hash] -
gotofritz revised this gist
May 23, 2016 . 1 changed file with 5 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ # from http://stackoverflow.com/a/5493663/345007 # --follow deals with name changes # -p does whole diffs # -- stops input and treats rest as arguments (i.e., filenames) git log --follow -p -- file -
gotofritz revised this gist
May 20, 2016 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ # tells you name of current repo git rev-parse --abbrev-ref HEAD -
gotofritz created this gist
May 4, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ function git-sync { # Checks name of current branch repo=`git rev-parse --abbrev-ref HEAD` # If this is a fork, there must be an 'original' (in git jargon an 'upstream') somewhere. # This assumes the git upstream was set with `git remote add upstream git@xxxx` # And that the master is used to sync with upstream, with everyone working on branches git checkout master && git pull origin master && git fetch upstream && git merge upstream/master && git push origin master # If you were in a branch, go back to it, and merge what you have just fetched if [ '$repo' != 'master' ]; then git checkout $repo && git merge origin master && git push origin $repo fi git status }