Last active
August 22, 2017 18:33
-
-
Save gotofritz/f8a307cd6d20f12db6cb366e18bc148f to your computer and use it in GitHub Desktop.
Git bits and pieces
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 characters
| # tells you name of current repo | |
| 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 characters
| # 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 |
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 characters
| # 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] |
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 characters
| # after your pull creates a lot of conflincts, if you just want to accept other devs' changes | |
| grep -lr '<<<<<<<' . | xargs git checkout --theirs |
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 characters
| # 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" | |
| # 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") |
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 characters
| 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 | |
| } |
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 characters
| # list branches which contains a commit | |
| git branch --contains <commit> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment