diff --git a/.doxie.render.js b/.doxie.render.js index ad9ac8b..82673fa 100644 --- a/.doxie.render.js +++ b/.doxie.render.js @@ -7,13 +7,18 @@ function escapeStr(str) { var render = function(data) { var data = data.data; - return [ + var tips = [ '## ' + data.title, '```sh', data.tip, '```', '\n' - ].join('\n'); + ]; + Array.isArray(data.alternatives) && tips.push(['__Alternatives:__']) && + data.alternatives.map(function(alternative){ + tips = tips.concat(['```sh',alternative,'```','\n']) + }); + return tips.join('\n'); }; module.exports = render; diff --git a/.doxie.render.toc.js b/.doxie.render.toc.js index a5cd205..bc74e84 100644 --- a/.doxie.render.toc.js +++ b/.doxie.render.toc.js @@ -1,11 +1,18 @@ -var tips = require('./tips.json'); +// from https://gist.github.com/mathewbyrne/1280286 +slugify = function(text){ + return text.toString().toLowerCase() + .replace(/\s+/g, '-') // Replace spaces with - + .replace(/[^\w\-]+/g, '') // Remove all non-word chars + .replace(/\-\-+/g, '-') // Replace multiple - with single - + .replace(/^-+/, '') // Trim - from start of text + .replace(/-+$/, ''); // Trim - from end of text +} var render = function(data) { var data = data.data; - var out = '* [' + data.title + '](https://github.com/git-tips/tips#' + data.title + ')\n'; + var out = '* [' + data.title + '](#' + slugify(data.title) + ')\n'; - if (tips[tips.length -1].title === data.title) out = out + '\n'; return out; }; diff --git a/.gitignore b/.gitignore index 93f1361..67d713f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +.idea node_modules npm-debug.log diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9097a64 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "eslint.enable": false, + "vsicons.presets.angular": false +} \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..e96f702 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at hemanth.hm@gmail.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..be0215a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2015 Hemanth.HM + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md index 14dbb90..757ef31 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,183 @@ ## git-tips > Collection of `git-tips`, want to add your tips? Checkout [contributing.md](./contributing.md) +[English](http://git.io/git-tips) | [中文](https://github.com/521xueweihan/git-tips) | [Русский](https://github.com/Imangazaliev/git-tips) | [한국어](https://github.com/mingrammer/git-tips) | [Tiếng Việt](https://github.com/hprobotic/git-tips) | [日本語](https://github.com/isotai/git-tips) | [नेपाली](https://github.com/amarduwal/git-tips) | [Polski](https://github.com/mbiesiad/tips) | [فارسی](https://github.com/javadnikbakht/git-tips) + +### __Tools:__ + +* [git-tip](https://www.npmjs.com/package/git-tip) - A handy CLI to make optimum use of these tips. ([Here in Docker container](https://github.com/djoudi5/docker-git-tip)) + +P.S: All these commands are tested on `git version 2.7.4 (Apple Git-66)`. + -* [Overwrite pull](https://github.com/git-tips/tips#Overwrite pull) -* [List of all the files changed in a commit](https://github.com/git-tips/tips#List of all the files changed in a commit) -* [Git reset first commit](https://github.com/git-tips/tips#Git reset first commit) -* [List all the conflicted files](https://github.com/git-tips/tips#List all the conflicted files) -* [List all branches that are already merged into master](https://github.com/git-tips/tips#List all branches that are already merged into master) -* [Quickly switch to the previous branch](https://github.com/git-tips/tips#Quickly switch to the previous branch) -* [Remove branches that have already been merged with master](https://github.com/git-tips/tips#Remove branches that have already been merged with master) -* [List all branches and their upstreams, as well as last commit on branch](https://github.com/git-tips/tips#List all branches and their upstreams, as well as last commit on branch) -* [Track upstream branch](https://github.com/git-tips/tips#Track upstream branch) +* [Everyday Git in twenty commands or so](#everyday-git-in-twenty-commands-or-so) +* [Show helpful guides that come with Git](#show-helpful-guides-that-come-with-git) +* [Search change by content](#search-change-by-content) +* [Show changes over time for specific file](#show-changes-over-time-for-specific-file) +* [Remove sensitive data from history, after a push](#remove-sensitive-data-from-history-after-a-push) +* [Sync with remote, overwrite local changes](#sync-with-remote-overwrite-local-changes) +* [List of all files till a commit](#list-of-all-files-till-a-commit) +* [Git reset first commit](#git-reset-first-commit) +* [Reset: preserve uncommitted local changes](#reset-preserve-uncommitted-local-changes) +* [List all the conflicted files](#list-all-the-conflicted-files) +* [List of all files changed in a commit](#list-of-all-files-changed-in-a-commit) +* [Unstaged changes since last commit](#unstaged-changes-since-last-commit) +* [Changes staged for commit](#changes-staged-for-commit) +* [Show both staged and unstaged changes](#show-both-staged-and-unstaged-changes) +* [List all branches that are already merged into master](#list-all-branches-that-are-already-merged-into-master) +* [Quickly switch to the previous branch](#quickly-switch-to-the-previous-branch) +* [Remove branches that have already been merged with master](#remove-branches-that-have-already-been-merged-with-master) +* [List all branches and their upstreams, as well as last commit on branch](#list-all-branches-and-their-upstreams-as-well-as-last-commit-on-branch) +* [Track upstream branch](#track-upstream-branch) +* [Delete local branch](#delete-local-branch) +* [Delete remote branch](#delete-remote-branch) +* [Create local tag](#create-local-tag) +* [Delete local tag](#delete-local-tag) +* [Delete remote tag](#delete-remote-tag) +* [Undo local changes with the last content in head](#undo-local-changes-with-the-last-content-in-head) +* [Revert: Undo a commit by creating a new commit](#revert-undo-a-commit-by-creating-a-new-commit) +* [Reset: Discard commits, advised for private branch](#reset-discard-commits-advised-for-private-branch) +* [Reword the previous commit message](#reword-the-previous-commit-message) +* [See commit history for just the current branch](#see-commit-history-for-just-the-current-branch) +* [Amend author.](#amend-author) +* [Reset author, after author has been changed in the global config.](#reset-author-after-author-has-been-changed-in-the-global-config) +* [Changing a remote's URL](#changing-a-remotes-url) +* [Get list of all remote references](#get-list-of-all-remote-references) +* [Get list of all local and remote branches](#get-list-of-all-local-and-remote-branches) +* [Get only remote branches](#get-only-remote-branches) +* [Stage parts of a changed file, instead of the entire file](#stage-parts-of-a-changed-file-instead-of-the-entire-file) +* [Get git bash completion](#get-git-bash-completion) +* [What changed since two weeks?](#what-changed-since-two-weeks) +* [See all commits made since forking from master](#see-all-commits-made-since-forking-from-master) +* [Pick commits across branches using cherry-pick](#pick-commits-across-branches-using-cherry-pick) +* [Find out branches containing commit-hash](#find-out-branches-containing-commit-hash) +* [Git Aliases](#git-aliases) +* [Saving current state of tracked files without commiting](#saving-current-state-of-tracked-files-without-commiting) +* [Saving current state of unstaged changes to tracked files](#saving-current-state-of-unstaged-changes-to-tracked-files) +* [Saving current state including untracked files](#saving-current-state-including-untracked-files) +* [Saving current state with message](#saving-current-state-with-message) +* [Saving current state of all files (ignored, untracked, and tracked)](#saving-current-state-of-all-files-ignored-untracked-and-tracked) +* [Show list of all saved stashes](#show-list-of-all-saved-stashes) +* [Show the contents of any stash in patch form](#show-the-contents-of-any-stash-in-patch-form) +* [Apply any stash without deleting from the stashed list](#apply-any-stash-without-deleting-from-the-stashed-list) +* [Apply last stashed state and delete it from stashed list](#apply-last-stashed-state-and-delete-it-from-stashed-list) +* [Delete all stored stashes](#delete-all-stored-stashes) +* [Grab a single file from a stash](#grab-a-single-file-from-a-stash) +* [Show all tracked files](#show-all-tracked-files) +* [Show all untracked files](#show-all-untracked-files) +* [Show all ignored files](#show-all-ignored-files) +* [Create new working tree from a repository (git 2.5)](#create-new-working-tree-from-a-repository-git-25) +* [Create new working tree from HEAD state](#create-new-working-tree-from-head-state) +* [Untrack files without deleting](#untrack-files-without-deleting) +* [Before deleting untracked files/directory, do a dry run to get the list of these files/directories](#before-deleting-untracked-filesdirectory-do-a-dry-run-to-get-the-list-of-these-filesdirectories) +* [Forcefully remove untracked files](#forcefully-remove-untracked-files) +* [Forcefully remove untracked directory](#forcefully-remove-untracked-directory) +* [Update all the submodules](#update-all-the-submodules) +* [Show all commits in the current branch yet to be merged to master](#show-all-commits-in-the-current-branch-yet-to-be-merged-to-master) +* [Rename a branch](#rename-a-branch) +* [Rebases 'feature' to 'master' and merges it in to master ](#rebases-feature-to-master-and-merges-it-in-to-master) +* [Archive the `master` branch](#archive-the-master-branch) +* [Modify previous commit without modifying the commit message](#modify-previous-commit-without-modifying-the-commit-message) +* [Prunes references to remove branches that have been deleted in the remote.](#prunes-references-to-remove-branches-that-have-been-deleted-in-the-remote) +* [Delete local branches that has been squash and merged in the remote.](#delete-local-branches-that-has-been-squash-and-merged-in-the-remote) +* [Retrieve the commit hash of the initial revision.](#retrieve-the-commit-hash-of-the-initial-revision) +* [Visualize the version tree.](#visualize-the-version-tree) +* [Visualize the tree including commits that are only referenced from reflogs](#visualize-the-tree-including-commits-that-are-only-referenced-from-reflogs) +* [Deploying git tracked subfolder to gh-pages](#deploying-git-tracked-subfolder-to-gh-pages) +* [Adding a project to repo using subtree](#adding-a-project-to-repo-using-subtree) +* [Get latest changes in your repo for a linked project using subtree](#get-latest-changes-in-your-repo-for-a-linked-project-using-subtree) +* [Export a branch with history to a file.](#export-a-branch-with-history-to-a-file) +* [Import from a bundle](#import-from-a-bundle) +* [Get the name of current branch.](#get-the-name-of-current-branch) +* [Ignore one file on commit (e.g. Changelog).](#ignore-one-file-on-commit-eg-changelog) +* [Stash changes before rebasing](#stash-changes-before-rebasing) +* [Fetch pull request by ID to a local branch](#fetch-pull-request-by-id-to-a-local-branch) +* [Show the most recent tag on the current branch.](#show-the-most-recent-tag-on-the-current-branch) +* [Show inline word diff.](#show-inline-word-diff) +* [Show changes using common diff tools.](#show-changes-using-common-diff-tools) +* [Don’t consider changes for tracked file.](#dont-consider-changes-for-tracked-file) +* [Undo assume-unchanged.](#undo-assume-unchanged) +* [Clean the files from `.gitignore`.](#clean-the-files-from-gitignore) +* [Restore deleted file.](#restore-deleted-file) +* [Restore file to a specific commit-hash](#restore-file-to-a-specific-commit-hash) +* [Always rebase instead of merge on pull.](#always-rebase-instead-of-merge-on-pull) +* [List all the alias and configs.](#list-all-the-alias-and-configs) +* [Make git case sensitive.](#make-git-case-sensitive) +* [Add custom editors.](#add-custom-editors) +* [Auto correct typos.](#auto-correct-typos) +* [Check if the change was a part of a release.](#check-if-the-change-was-a-part-of-a-release) +* [Dry run. (any command that supports dry-run flag should do.)](#dry-run-any-command-that-supports-dry-run-flag-should-do) +* [Marks your commit as a fix of a previous commit.](#marks-your-commit-as-a-fix-of-a-previous-commit) +* [Squash fixup commits normal commits.](#squash-fixup-commits-normal-commits) +* [Skip staging area during commit.](#skip-staging-area-during-commit) +* [Interactive staging.](#interactive-staging) +* [List ignored files.](#list-ignored-files) +* [Status of ignored files.](#status-of-ignored-files) +* [Commits in Branch1 that are not in Branch2](#commits-in-branch1-that-are-not-in-branch2) +* [List n last commits](#list-n-last-commits) +* [Reuse recorded resolution, record and reuse previous conflicts resolutions.](#reuse-recorded-resolution-record-and-reuse-previous-conflicts-resolutions) +* [Open all conflicted files in an editor.](#open-all-conflicted-files-in-an-editor) +* [Count unpacked number of objects and their disk consumption.](#count-unpacked-number-of-objects-and-their-disk-consumption) +* [Prune all unreachable objects from the object database.](#prune-all-unreachable-objects-from-the-object-database) +* [Instantly browse your working repository in gitweb.](#instantly-browse-your-working-repository-in-gitweb) +* [View the GPG signatures in the commit log](#view-the-gpg-signatures-in-the-commit-log) +* [Remove entry in the global config.](#remove-entry-in-the-global-config) +* [Checkout a new branch without any history](#checkout-a-new-branch-without-any-history) +* [Extract file from another branch.](#extract-file-from-another-branch) +* [List only the root and merge commits.](#list-only-the-root-and-merge-commits) +* [Change previous two commits with an interactive rebase.](#change-previous-two-commits-with-an-interactive-rebase) +* [List all branch is WIP](#list-all-branch-is-wip) +* [Find guilty with binary search](#find-guilty-with-binary-search) +* [Bypass pre-commit and commit-msg githooks](#bypass-pre-commit-and-commit-msg-githooks) +* [List commits and changes to a specific file (even through renaming)](#list-commits-and-changes-to-a-specific-file-even-through-renaming) +* [Clone a single branch](#clone-a-single-branch) +* [Create and switch new branch](#create-and-switch-new-branch) +* [Ignore file mode changes on commits](#ignore-file-mode-changes-on-commits) +* [Turn off git colored terminal output](#turn-off-git-colored-terminal-output) +* [Specific color settings](#specific-color-settings) +* [Show all local branches ordered by recent commits](#show-all-local-branches-ordered-by-recent-commits) +* [Find lines matching the pattern (regex or string) in tracked files](#find-lines-matching-the-pattern-regex-or-string-in-tracked-files) +* [Clone a shallow copy of a repository](#clone-a-shallow-copy-of-a-repository) +* [Search Commit log across all branches for given text](#search-commit-log-across-all-branches-for-given-text) +* [Get first commit in a branch (from master)](#get-first-commit-in-a-branch-from-master) +* [Unstaging Staged file](#unstaging-staged-file) +* [Force push to Remote Repository](#force-push-to-remote-repository) +* [Adding Remote name](#adding-remote-name) +* [List all currently configured remotes](#list-all-currently-configured-remotes) +* [Show the author, time and last revision made to each line of a given file](#show-the-author-time-and-last-revision-made-to-each-line-of-a-given-file) +* [Group commits by authors and title](#group-commits-by-authors-and-title) +* [Forced push but still ensure you don't overwrite other's work](#forced-push-but-still-ensure-you-dont-overwrite-others-work) +* [Show how many lines does an author contribute](#show-how-many-lines-does-an-author-contribute) +* [Revert: Reverting an entire merge](#revert-reverting-an-entire-merge) +* [Number of commits in a branch](#number-of-commits-in-a-branch) +* [Alias: git undo](#alias-git-undo) +* [Add object notes](#add-object-notes) +* [Show all the git-notes](#show-all-the-git-notes) +* [Apply commit from another repository](#apply-commit-from-another-repository) +* [Specific fetch reference](#specific-fetch-reference) +* [Find common ancestor of two branches](#find-common-ancestor-of-two-branches) +* [List unpushed git commits](#list-unpushed-git-commits) +* [Add everything, but whitespace changes](#add-everything-but-whitespace-changes) +* [Edit [local/global] git config](#edit-localglobal-git-config) +* [blame on certain range](#blame-on-certain-range) +* [Show a Git logical variable.](#show-a-git-logical-variable) +* [Preformatted patch file.](#preformatted-patch-file) +* [Get the repo name.](#get-the-repo-name) +* [logs between date range](#logs-between-date-range) +* [Exclude author from logs](#exclude-author-from-logs) +* [Generates a summary of pending changes](#generates-a-summary-of-pending-changes) +* [List references in a remote repository](#list-references-in-a-remote-repository) +* [Backup untracked files.](#backup-untracked-files) +* [List all git aliases](#list-all-git-aliases) +* [Show git status short](#show-git-status-short) +* [Checkout a commit prior to a day ago](#checkout-a-commit-prior-to-a-day-ago) +* [Push the current branch to the same name on the remote repository](#push-the-current-branch-to-the-same-name-on-the-remote-repository) +* [Push a new local branch to remote repository and track](#push-a-new-local-branch-to-remote-repository-and-track) +* [Change a branch base](#change-a-branch-base) +* [Use SSH instead of HTTPs for remotes](#use-ssh-instead-of-https-for-remotes) +* [Update a submodule to the latest commit](#update-a-submodule-to-the-latest-commit) +* [Prevent auto replacing LF with CRLF](#prevent-auto-replacing-lf-with-crlf) @@ -19,12 +185,37 @@ -## Overwrite pull +## Everyday Git in twenty commands or so +```sh +git help everyday +``` + +## Show helpful guides that come with Git +```sh +git help -g +``` + +## Search change by content +```sh +git log -S'' +``` + +## Show changes over time for specific file +```sh +git log -p +``` + +## Remove sensitive data from history, after a push ```sh -git fetch --all && git reset --hard origin/master +git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all ``` -## List of all the files changed in a commit +## Sync with remote, overwrite local changes +```sh +git fetch origin && git reset --hard origin/master && git clean -f -d +``` + +## List of all files till a commit ```sh git ls-tree --name-only -r ``` @@ -34,14 +225,45 @@ git ls-tree --name-only -r git update-ref -d HEAD ``` +## Reset: preserve uncommitted local changes +```sh +git reset --keep +``` + ## List all the conflicted files ```sh git diff --name-only --diff-filter=U ``` +## List of all files changed in a commit +```sh +git diff-tree --no-commit-id --name-only -r +``` + +## Unstaged changes since last commit +```sh +git diff +``` + +## Changes staged for commit +```sh +git diff --cached +``` + + +__Alternatives:__ +```sh +git diff --staged +``` + +## Show both staged and unstaged changes +```sh +git diff HEAD +``` + ## List all branches that are already merged into master ```sh -git checkout master && git branch --merged +git branch --merged master ``` ## Quickly switch to the previous branch @@ -49,9 +271,21 @@ git checkout master && git branch --merged git checkout - ``` + +__Alternatives:__ +```sh +git checkout @{-1} +``` + ## Remove branches that have already been merged with master ```sh -git branch --merged | grep -v '\*' | xargs -n 1 git branch -d +git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -d +``` + + +__Alternatives:__ +```sh +git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d # will not delete master if master is not checked out ``` ## List all branches and their upstreams, as well as last commit on branch @@ -64,5 +298,971 @@ git branch -vv git branch -u origin/mybranch ``` +## Delete local branch +```sh +git branch -d +``` + +## Delete remote branch +```sh +git push origin --delete +``` + + +__Alternatives:__ +```sh +git push origin : +``` + + +```sh +git branch -dr +``` + +## Create local tag +```sh +git tag +``` + +## Delete local tag +```sh +git tag -d +``` + +## Delete remote tag +```sh +git push origin :refs/tags/ +``` + +## Undo local changes with the content in index(staging) +```sh +git checkout -- +``` + +## Revert: Undo a commit by creating a new commit +```sh +git revert +``` + +## Reset: Discard commits, advised for private branch +```sh +git reset +``` + +## Reword the previous commit message +```sh +git commit -v --amend +``` + +## See commit history for just the current branch +```sh +git cherry -v master +``` + +## Amend author. +```sh +git commit --amend --author='Author Name ' +``` + +## Reset author, after author has been changed in the global config. +```sh +git commit --amend --reset-author --no-edit +``` + +## Changing a remote's URL +```sh +git remote set-url origin +``` + +## Get list of all remote references +```sh +git remote +``` + + +__Alternatives:__ +```sh +git remote show +``` + +## Get list of all local and remote branches +```sh +git branch -a +``` + +## Get only remote branches +```sh +git branch -r +``` + +## Stage parts of a changed file, instead of the entire file +```sh +git add -p +``` + +## Get git bash completion +```sh +curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc +``` + +## What changed since two weeks? +```sh +git log --no-merges --raw --since='2 weeks ago' +``` + + +__Alternatives:__ +```sh +git whatchanged --since='2 weeks ago' +``` + +## See all commits made since forking from master +```sh +git log --no-merges --stat --reverse master.. +``` + +## Pick commits across branches using cherry-pick +```sh +git checkout && git cherry-pick +``` + +## Find out branches containing commit-hash +```sh +git branch -a --contains +``` + + +__Alternatives:__ +```sh +git branch --contains +``` + +## Git Aliases +```sh +git config --global alias. +git config --global alias.st status +``` + +## Saving current state of tracked files without commiting +```sh +git stash +``` + + +__Alternatives:__ +```sh +git stash push +``` + +## Saving current state of unstaged changes to tracked files +```sh +git stash -k +``` + + +__Alternatives:__ +```sh +git stash --keep-index +``` + + +```sh +git stash push --keep-index +``` + +## Saving current state including untracked files +```sh +git stash -u +``` + + +__Alternatives:__ +```sh +git stash push -u +``` + + +```sh +git stash push --include-untracked +``` + +## Saving current state with message +```sh +git stash push -m +``` + + +__Alternatives:__ +```sh +git stash push --message +``` + +## Saving current state of all files (ignored, untracked, and tracked) +```sh +git stash -a +``` + + +__Alternatives:__ +```sh +git stash --all +``` + + +```sh +git stash push --all +``` + +## Show list of all saved stashes +```sh +git stash list +``` + +## Show the contents of any stash in patch form +```sh +git stash show -p +``` + +## Apply any stash without deleting from the stashed list +```sh +git stash apply +``` + +## Apply last stashed state and delete it from stashed list +```sh +git stash pop +``` + + +__Alternatives:__ +```sh +git stash apply stash@{0} && git stash drop stash@{0} +``` + +## Delete all stored stashes +```sh +git stash clear +``` + + +__Alternatives:__ +```sh +git stash drop +``` + +## Grab a single file from a stash +```sh +git checkout -- +``` + + +__Alternatives:__ +```sh +git checkout stash@{0} -- +``` + +## Show all tracked files +```sh +git ls-files -t +``` + +## Show all untracked files +```sh +git ls-files --others +``` + +## Show all ignored files +```sh +git ls-files --others -i --exclude-standard +``` + +## Create new working tree from a repository (git 2.5) +```sh +git worktree add -b +``` + +## Create new working tree from HEAD state +```sh +git worktree add --detach HEAD +``` + +## Untrack files without deleting +```sh +git rm --cached +``` + + +__Alternatives:__ +```sh +git rm --cached -r +``` + +## Before deleting untracked files/directory, do a dry run to get the list of these files/directories +```sh +git clean -n +``` + +## Forcefully remove untracked files +```sh +git clean -f +``` + +## Forcefully remove untracked directory +```sh +git clean -f -d +``` + +## Update all the submodules +```sh +git submodule foreach git pull +``` + + +__Alternatives:__ +```sh +git submodule update --init --recursive +``` + + +```sh +git submodule update --remote +``` + +## Show all commits in the current branch yet to be merged to master +```sh +git cherry -v master +``` + + +__Alternatives:__ +```sh +git cherry -v master +``` + +## Rename a branch +```sh +git branch -m +``` + + +__Alternatives:__ +```sh +git branch -m [] +``` + +## Rebases 'feature' to 'master' and merges it in to master +```sh +git rebase master feature && git checkout master && git merge - +``` + +## Archive the `master` branch +```sh +git archive master --format=zip --output=master.zip +``` + +## Modify previous commit without modifying the commit message +```sh +git add --all && git commit --amend --no-edit +``` + +## Prunes references to remove branches that have been deleted in the remote. +```sh +git fetch -p +``` + + +__Alternatives:__ +```sh +git remote prune origin +``` + +## Delete local branches that has been squash and merged in the remote. +```sh +git branch -vv | grep ': gone]' | awk '{print }' | xargs git branch -D +``` + +## Retrieve the commit hash of the initial revision. +```sh + git rev-list --reverse HEAD | head -1 +``` + + +__Alternatives:__ +```sh +git rev-list --max-parents=0 HEAD +``` + + +```sh +git log --pretty=oneline | tail -1 | cut -c 1-40 +``` + + +```sh +git log --pretty=oneline --reverse | head -1 | cut -c 1-40 +``` + +## Visualize the version tree. +```sh +git log --pretty=oneline --graph --decorate --all +``` + + +__Alternatives:__ +```sh +gitk --all +``` + + +```sh +git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d' +``` + +## Visualize the tree including commits that are only referenced from reflogs +```sh +git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all) +``` + +## Deploying git tracked subfolder to gh-pages +```sh +git subtree push --prefix subfolder_name origin gh-pages +``` + +## Adding a project to repo using subtree +```sh +git subtree add --prefix=/ --squash git@github.com:/.git master +``` + +## Get latest changes in your repo for a linked project using subtree +```sh +git subtree pull --prefix=/ --squash git@github.com:/.git master +``` + +## Export a branch with history to a file. +```sh +git bundle create +``` + +## Import from a bundle +```sh +git clone repo.bundle -b +``` + +## Get the name of current branch. +```sh +git rev-parse --abbrev-ref HEAD +``` + +## Ignore one file on commit (e.g. Changelog). +```sh +git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog +``` + +## Stash changes before rebasing +```sh +git rebase --autostash +``` + +## Fetch pull request by ID to a local branch +```sh +git fetch origin pull//head: +``` + + +__Alternatives:__ +```sh +git pull origin pull//head: +``` + +## Show the most recent tag on the current branch. +```sh +git describe --tags --abbrev=0 +``` + +## Show inline word diff. +```sh +git diff --word-diff +``` + +## Show changes using common diff tools. +```sh +git difftool [-t ] +``` + +## Don’t consider changes for tracked file. +```sh +git update-index --assume-unchanged +``` + +## Undo assume-unchanged. +```sh +git update-index --no-assume-unchanged +``` + +## Clean the files from `.gitignore`. +```sh +git clean -X -f +``` + +## Restore deleted file. +```sh +git checkout -- +``` + +## Restore file to a specific commit-hash +```sh +git checkout -- +``` + +## Always rebase instead of merge on pull. +```sh +git config --global pull.rebase true +``` + + +__Alternatives:__ +```sh +#git < 1.7.9 +git config --global branch.autosetuprebase always +``` + +## List all the alias and configs. +```sh +git config --list +``` + +## Make git case sensitive. +```sh +git config --global core.ignorecase false +``` + +## Add custom editors. +```sh +git config --global core.editor '$EDITOR' +``` + +## Auto correct typos. +```sh +git config --global help.autocorrect 1 +``` + +## Check if the change was a part of a release. +```sh +git name-rev --name-only +``` + +## Dry run. (any command that supports dry-run flag should do.) +```sh +git clean -fd --dry-run +``` + +## Marks your commit as a fix of a previous commit. +```sh +git commit --fixup +``` + +## Squash fixup commits normal commits. +```sh +git rebase -i --autosquash +``` + +## Skip staging area during commit. +```sh +git commit --only +``` + +## Interactive staging. +```sh +git add -i +``` + +## List ignored files. +```sh +git check-ignore * +``` + +## Status of ignored files. +```sh +git status --ignored +``` + +## Commits in Branch1 that are not in Branch2 +```sh +git log Branch1 ^Branch2 +``` + +## List n last commits +```sh +git log - +``` + + +__Alternatives:__ +```sh +git log -n +``` + +## Reuse recorded resolution, record and reuse previous conflicts resolutions. +```sh +git config --global rerere.enabled 1 +``` + +## Open all conflicted files in an editor. +```sh +git diff --name-only | uniq | xargs $EDITOR +``` + +## Count unpacked number of objects and their disk consumption. +```sh +git count-objects --human-readable +``` + +## Prune all unreachable objects from the object database. +```sh +git gc --prune=now --aggressive +``` + +## Instantly browse your working repository in gitweb. +```sh +git instaweb [--local] [--httpd=] [--port=] [--browser=] +``` + +## View the GPG signatures in the commit log +```sh +git log --show-signature +``` + +## Remove entry in the global config. +```sh +git config --global --unset +``` + +## Checkout a new branch without any history +```sh +git checkout --orphan +``` + +## Extract file from another branch. +```sh +git show : +``` + +## List only the root and merge commits. +```sh +git log --first-parent +``` + +## Change previous two commits with an interactive rebase. +```sh +git rebase --interactive HEAD~2 +``` + +## List all branch is WIP +```sh +git checkout master && git branch --no-merged +``` + +## Find guilty with binary search +```sh +git bisect start # Search start +git bisect bad # Set point to bad commit +git bisect good v2.6.13-rc2 # Set point to good commit|tag +git bisect bad # Say current state is bad +git bisect good # Say current state is good +git bisect reset # Finish search + +``` + +## Bypass pre-commit and commit-msg githooks +```sh +git commit --no-verify +``` + +## List commits and changes to a specific file (even through renaming) +```sh +git log --follow -p -- +``` + +## Clone a single branch +```sh +git clone -b --single-branch https://github.com/user/repo.git +``` + +## Create and switch new branch +```sh +git checkout -b +``` + + +__Alternatives:__ +```sh +git branch && git checkout +``` + +```sh +git switch -c +``` + +## Ignore file mode changes on commits +```sh +git config core.fileMode false +``` + +## Turn off git colored terminal output +```sh +git config --global color.ui false +``` + +## Specific color settings +```sh +git config --global +``` + +## Show all local branches ordered by recent commits +```sh +git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ +``` + +## Find lines matching the pattern (regex or string) in tracked files +```sh +git grep --heading --line-number 'foo bar' +``` + +## Clone a shallow copy of a repository +```sh +git clone https://github.com/user/repo.git --depth 1 +``` + +## Search Commit log across all branches for given text +```sh +git log --all --grep='' +``` + +## Get first commit in a branch (from master) +```sh +git log --oneline master.. | tail -1 +``` + + +__Alternatives:__ +```sh +git log --reverse master.. | head -6 +``` + +## Unstaging Staged file +```sh +git reset HEAD +``` + +## Force push to Remote Repository +```sh +git push -f +``` + +## Adding Remote name +```sh +git remote add +``` + +## List all currently configured remotes +```sh +git remote -v +``` + +## Show the author, time and last revision made to each line of a given file +```sh +git blame +``` + +## Group commits by authors and title +```sh +git shortlog +``` + +## Forced push but still ensure you don't overwrite other's work +```sh +git push --force-with-lease +``` + +## Show how many lines does an author contribute +```sh +git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += ; subs += ; loc += - } END { printf "added lines: %s removed lines: %s total lines: %s +", add, subs, loc }' - +``` + + +__Alternatives:__ +```sh +git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | awk '{ add += ; subs += ; loc += - } END { printf "added lines: %s, removed lines: %s, total lines: %s +", add, subs, loc }' - # on Mac OSX +``` + +## Revert: Reverting an entire merge +```sh +git revert -m 1 +``` + +## Number of commits in a branch +```sh +git rev-list --count +``` + +## Alias: git undo +```sh +git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f' +``` + +## Add object notes +```sh +git notes add -m 'Note on the previous commit....' +``` + +## Show all the git-notes +```sh +git log --show-notes='*' +``` + +## Apply commit from another repository +```sh +git --git-dir=/.git format-patch -k -1 --stdout | git am -3 -k +``` + +## Specific fetch reference +```sh +git fetch origin master:refs/remotes/origin/mymaster +``` + +## Find common ancestor of two branches +```sh +git merge-base +``` + +## List unpushed git commits +```sh +git log --branches --not --remotes +``` + + +__Alternatives:__ +```sh +git log @{u}.. +``` + + +```sh +git cherry -v +``` + +## Add everything, but whitespace changes +```sh +git diff --ignore-all-space | git apply --cached +``` + +## Edit [local/global] git config +```sh +git config [--global] --edit +``` + +## blame on certain range +```sh +git blame -L , +``` + +## Show a Git logical variable. +```sh +git var -l | +``` + +## Preformatted patch file. +```sh +git format-patch -M upstream..topic +``` + +## Get the repo name. +```sh +git rev-parse --show-toplevel +``` + +## logs between date range +```sh +git log --since='FEB 1 2017' --until='FEB 14 2017' +``` + +## Exclude author from logs +```sh +git log --perl-regexp --author='^((?!excluded-author-regex).*) + +``` + +## Generates a summary of pending changes +```sh +git request-pull v1.0 https://git.ko.xz/project master:for-linus +``` + +## List references in a remote repository +```sh +git ls-remote git://git.kernel.org/pub/scm/git/git.git +``` + +## Backup untracked files. +```sh +git ls-files --others -i --exclude-standard | xargs zip untracked.zip +``` + +## List all git aliases +```sh +git config -l | grep alias | sed 's/^alias\.//g' +``` + + +__Alternatives:__ +```sh +git config -l | grep alias | cut -d '.' -f 2 +``` + +## Show git status short +```sh +git status --short --branch +``` + +## Checkout a commit prior to a day ago +```sh +git checkout master@{yesterday} +``` + +## Push the current branch to the same name on the remote repository +```sh +git push origin HEAD +``` + +## Push a new local branch to remote repository and track +```sh +git push -u origin +``` + +## Change a branch base +```sh +git rebase --onto +``` + +## Use SSH instead of HTTPs for remotes +```sh +git config --global url.'git@github.com:'.insteadOf 'https://github.com/' +``` + +## Update a submodule to the latest commit +```sh +cd +git pull origin +cd +git add +git commit -m "submodule updated" +``` + +## Prevent auto replacing LF with CRLF +```sh +git config --global core.autocrlf false +``` + diff --git a/contributing.md b/contributing.md index bdcd68b..f3bc85e 100644 --- a/contributing.md +++ b/contributing.md @@ -1,21 +1,21 @@ ## Easy steps: -* Clone this [repo](https://github.com/git-tips/tips.git): - ```sh - $ git clone https://github.com/git-tips/tips.git - ``` - -* Install the deps: +* [Fork](https://github.com/git-tips/tips/network) the repo. + +* Install the deps: ```sh $ cd tips && npm install ``` - + + :warning: don't fail to think that this is optional, because if you don't install the dependencies you won't get the benefit of auto-updating README and TOC and your PR will likely to not get merged because of that. + * Edit [tips.json](./tips.json) to add your tip in the below format: ```js { "title": , - "tip": + "tip": , + "alternatives": [Optional list of alternatives] } ``` diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..ec93f7f --- /dev/null +++ b/package-lock.json @@ -0,0 +1,301 @@ +{ + "name": "tips", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "101": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/101/-/101-1.6.3.tgz", + "integrity": "sha512-4dmQ45yY0Dx24Qxp+zAsNLlMF6tteCyfVzgbulvSyC7tCyd3V8sW76sS0tHq8NpcbXfWTKasfyfzU1Kd86oKzw==", + "dev": true, + "requires": { + "clone": "^1.0.2", + "deep-eql": "^0.1.3", + "keypather": "^1.10.2" + } + }, + "1-liners": { + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/1-liners/-/1-liners-0.3.6.tgz", + "integrity": "sha1-SDD+eLdTejaZ+IpdQqjtwa9mB/8=", + "dev": true + }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "array-find": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/array-find/-/array-find-1.0.0.tgz", + "integrity": "sha1-bI4obRHtdoMn+OYuzuhzU8o+eLg=", + "dev": true + }, + "base64-js": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-0.0.2.tgz", + "integrity": "sha1-Ak8Pcq+iW3X5wO5zzU9V7Bvtl4Q=", + "dev": true + }, + "bops": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/bops/-/bops-0.0.6.tgz", + "integrity": "sha1-CC0dVfoB5g29wuvC26N/ZZVUzzo=", + "dev": true, + "requires": { + "base64-js": "0.0.2", + "to-utf8": "0.0.1" + } + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "clone": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", + "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=", + "dev": true + }, + "concat-stream": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.2.1.tgz", + "integrity": "sha1-81EAtsRjeL+6i2uA+fDQzN8T3GA=", + "dev": true, + "requires": { + "bops": "0.0.6" + } + }, + "deep-eql": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-0.1.3.tgz", + "integrity": "sha1-71WKyrjeJSBs1xOQbXTlaTDrafI=", + "dev": true, + "requires": { + "type-detect": "0.1.1" + } + }, + "defined": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/defined/-/defined-1.0.0.tgz", + "integrity": "sha1-yY2bzvdWdBiOEQlpFRGZ45sfppM=", + "dev": true + }, + "doxie": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/doxie/-/doxie-0.2.4.tgz", + "integrity": "sha1-KZltv1dg/OdNvLTXnGAjHYoXu4U=", + "dev": true, + "requires": { + "1-liners": "^0.3.2", + "chalk": "^1.0.0", + "doxie-core": "^0.3.1", + "stream-to-json": "^0.0.1", + "tiny-error": "^0.2.1" + } + }, + "doxie-core": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/doxie-core/-/doxie-core-0.3.1.tgz", + "integrity": "sha1-PS+RQ+WF45Cpgwjcnk7zjxPPQss=", + "dev": true, + "requires": { + "1-liners": "^0.3.0", + "chalk": "^1.0.0", + "tiny-error": "^0.2.1" + } + }, + "doxie.append": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/doxie.append/-/doxie.append-0.1.0.tgz", + "integrity": "sha1-yHRoUEL18wlKTQwzNsPklMNpdOE=", + "dev": true, + "requires": { + "object-assign": "^3.0.0" + }, + "dependencies": { + "object-assign": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", + "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", + "dev": true + } + } + }, + "doxie.inject": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/doxie.inject/-/doxie.inject-0.1.1.tgz", + "integrity": "sha1-/QNYT4segOZEtcuUdpr+RH94oEc=", + "dev": true, + "requires": { + "1-liners": "^0.3.2", + "array-find": "^1.0.0", + "chalk": "^1.0.0", + "defined": "^1.0.0", + "object-assign": "^3.0.0", + "tiny-error": "^0.2.1" + }, + "dependencies": { + "object-assign": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", + "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", + "dev": true + } + } + }, + "doxie.output": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/doxie.output/-/doxie.output-0.3.0.tgz", + "integrity": "sha1-4H4Stn2qX8KLPsZn0HAv1ziZitE=", + "dev": true, + "requires": { + "1-liners": "^0.3.0", + "object-assign": "^3.0.0" + }, + "dependencies": { + "object-assign": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", + "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", + "dev": true + } + } + }, + "doxie.render": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/doxie.render/-/doxie.render-0.3.2.tgz", + "integrity": "sha1-Mva37g88NSSokT08grn6uqoKGPA=", + "dev": true, + "requires": { + "1-liners": "^0.3.1", + "chalk": "^1.0.0", + "object-assign": "^3.0.0", + "tiny-error": "^0.2.1" + }, + "dependencies": { + "object-assign": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz", + "integrity": "sha1-m+3VygiXlJvKR+f/QIBi1Un1h/I=", + "dev": true + } + } + }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "husky": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/husky/-/husky-5.2.0.tgz", + "integrity": "sha512-AM8T/auHXRBxlrfPVLKP6jt49GCM2Zz47m8G3FOMsLmTv8Dj/fKVWE0Rh2d4Qrvmy131xEsdQnb3OXRib67PGg==", + "dev": true + }, + "keypather": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/keypather/-/keypather-1.10.2.tgz", + "integrity": "sha1-4ESWMtSz5RbyHMAUznxWRP3c5hQ=", + "dev": true, + "requires": { + "101": "^1.0.0" + } + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "dev": true + }, + "once": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/once/-/once-1.3.3.tgz", + "integrity": "sha1-suJhVXzkwxTsgwTz+oJmPkKXyiA=", + "dev": true, + "requires": { + "wrappy": "1" + } + }, + "stream-to-json": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/stream-to-json/-/stream-to-json-0.0.1.tgz", + "integrity": "sha1-8DDyt47TjkkpPbiFZTarzCZ3FHM=", + "dev": true, + "requires": { + "concat-stream": "~1.2.0", + "once": "~1.3.0" + } + }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + }, + "tiny-error": { + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/tiny-error/-/tiny-error-0.2.3.tgz", + "integrity": "sha1-KHas/leFGwcUMTwVNd/HBgp8Cbs=", + "dev": true, + "requires": { + "101": "^1.0.0", + "object-assign": "^4.0.1" + } + }, + "to-utf8": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/to-utf8/-/to-utf8-0.0.1.tgz", + "integrity": "sha1-0Xrqcv8vujm55DYBvns/9y4ImFI=", + "dev": true + }, + "type-detect": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-0.1.1.tgz", + "integrity": "sha1-C6XsKohWQORw6k6FBZcZANrFiCI=", + "dev": true + }, + "wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "dev": true + } + } +} diff --git a/package.json b/package.json index 158ea8a..75efa09 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "test": "echo \"Error: no test specified\" && exit 1", "precommit": "npm run generate && git add README.md", "update-readme": "echo 'Updating the readme…'; doxie --render < ./tips.json --inject into README.md && echo '…done!'", - "update-toc": "echo 'Updating the table of contents…'; doxie --render .doxie.render.toc.js < ./tips.json --inject into README.md as toc && echo '…done!'", + "update-toc": "echo 'Updating the table of contents…'; doxie --render .doxie.render.toc.js < ./tips.json --append '\n' --inject into README.md as toc && echo '…done!'", "generate": "npm run update-readme; npm run update-toc" }, "repository": { @@ -29,9 +29,10 @@ "homepage": "https://github.com/git-tips/tips#readme", "devDependencies": { "doxie": "^0.2.2", + "doxie.append": "^0.1.0", "doxie.inject": "^0.1.1", "doxie.output": "^0.3.0", "doxie.render": "^0.3.0", - "husky": "^0.8.1" + "husky": "^5.0.9" } } diff --git a/tips.json b/tips.json index f1a77f9..7cf20b2 100644 --- a/tips.json +++ b/tips.json @@ -1,38 +1,535 @@ -[ - { - "title": "Overwrite pull", - "tip": "git fetch --all && git reset --hard origin/master" - }, - { - "title": "List of all the files changed in a commit", - "tip": "git ls-tree --name-only -r " - }, - { - "title": "Git reset first commit", - "tip": "git update-ref -d HEAD" - }, - { - "title": "List all the conflicted files", - "tip": "git diff --name-only --diff-filter=U" - }, - { - "title": "List all branches that are already merged into master", - "tip": "git checkout master && git branch --merged" - }, - { - "title": "Quickly switch to the previous branch", - "tip": "git checkout -" - }, - { - "title": "Remove branches that have already been merged with master", - "tip": "git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d" - }, - { - "title": "List all branches and their upstreams, as well as last commit on branch", - "tip": "git branch -vv" - }, - { - "title": "Track upstream branch", - "tip": "git branch -u origin/mybranch" - } +[{ + "title": "Everyday Git in twenty commands or so", + "tip": "git help everyday" + }, { + "title": "Show helpful guides that come with Git", + "tip": "git help -g" + }, { + "title": "Search change by content", + "tip": "git log -S''" + }, { + "title": "Show changes over time for specific file", + "tip": "git log -p " + }, { + "title": "Remove sensitive data from history, after a push", + "tip": "git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all" + }, { + "title": "Sync with remote, overwrite local changes", + "tip": "git fetch origin && git reset --hard origin/master && git clean -f -d" + }, { + "title": "List of all files till a commit", + "tip": "git ls-tree --name-only -r " + }, { + "title": "Git reset first commit", + "tip": "git update-ref -d HEAD" + }, { + "title": "Reset: preserve uncommitted local changes", + "tip": "git reset --keep " + }, { + "title": "List all the conflicted files", + "tip": "git diff --name-only --diff-filter=U" + }, { + "title": "List of all files changed in a commit", + "tip": "git diff-tree --no-commit-id --name-only -r " + }, { + "title": "Unstaged changes since last commit", + "tip": "git diff" + }, { + "title": "Changes staged for commit", + "tip": "git diff --cached", + "alternatives": ["git diff --staged"] + }, { + "title": "Show both staged and unstaged changes", + "tip": "git diff HEAD" + }, { + "title": "List all branches that are already merged into master", + "tip": "git branch --merged master" + }, { + "title": "Quickly switch to the previous branch", + "tip": "git checkout -", + "alternatives": ["git checkout @{-1}"] + }, { + "title": "Remove branches that have already been merged with master", + "tip": "git branch --merged master | grep -v '^\\*' | xargs -n 1 git branch -d", + "alternatives": ["git branch --merged master | grep -v '^\\*\\| master' | xargs -n 1 git branch -d # will not delete master if master is not checked out"] + }, { + "title": "List all branches and their upstreams, as well as last commit on branch", + "tip": "git branch -vv" + }, { + "title": "Track upstream branch", + "tip": "git branch -u origin/mybranch" + }, { + "title": "Delete local branch", + "tip": "git branch -d " + }, { + "title": "Delete remote branch", + "tip": "git push origin --delete ", + "alternatives": ["git push origin :", "git branch -dr "] + }, { + "title": "Create local tag", + "tip": "git tag " + }, { + "title": "Delete local tag", + "tip": "git tag -d " + }, { + "title": "Delete remote tag", + "tip": "git push origin :refs/tags/" + }, { + "title": "Undo local changes with the content in index(staging)", + "tip": "git checkout -- " + }, { + "title": "Revert: Undo a commit by creating a new commit", + "tip": "git revert " + }, { + "title": "Reset: Discard commits, advised for private branch", + "tip": "git reset " + }, { + "title": "Reword the previous commit message", + "tip": "git commit -v --amend" + }, { + "title": "See commit history for just the current branch", + "tip": "git cherry -v master" + }, { + "title": "Amend author.", + "tip": "git commit --amend --author='Author Name '" + }, { + "title": "Reset author, after author has been changed in the global config.", + "tip": "git commit --amend --reset-author --no-edit" + }, { + "title": "Changing a remote's URL", + "tip": "git remote set-url origin " + }, { + "title": "Get list of all remote references", + "tip": "git remote", + "alternatives": ["git remote show"] + }, { + "title": "Get list of all local and remote branches", + "tip": "git branch -a" + }, { + "title": "Get only remote branches", + "tip": "git branch -r" + }, { + "title": "Stage parts of a changed file, instead of the entire file", + "tip": "git add -p" + }, { + "title": "Get git bash completion", + "tip": "curl -L http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc" + }, { + "title": "What changed since two weeks?", + "tip": "git log --no-merges --raw --since='2 weeks ago'", + "alternatives": ["git whatchanged --since='2 weeks ago'"] + }, { + "title": "See all commits made since forking from master", + "tip": "git log --no-merges --stat --reverse master.." + }, { + "title": "Pick commits across branches using cherry-pick", + "tip": "git checkout && git cherry-pick " + }, { + "title": "Find out branches containing commit-hash", + "tip": "git branch -a --contains ", + "alternatives": ["git branch --contains "] + }, { + "title": "Git Aliases", + "tip": "git config --global alias. \ngit config --global alias.st status" + }, { + "title": "Saving current state of tracked files without committing", + "tip": "git stash", + "alternatives": ["git stash push"] + }, { + "title": "Saving current state of unstaged changes to tracked files", + "tip": "git stash -k", + "alternatives": ["git stash --keep-index", "git stash push --keep-index"] + }, { + "title": "Saving current state including untracked files", + "tip": "git stash -u", + "alternatives": ["git stash push -u", "git stash push --include-untracked"] + }, { + "title": "Saving current state with message", + "tip": "git stash push -m ", + "alternatives": ["git stash push --message "] + }, { + "title": "Saving current state of all files (ignored, untracked, and tracked)", + "tip": "git stash -a", + "alternatives": ["git stash --all", "git stash push --all"] + }, { + "title": "Show list of all saved stashes", + "tip": "git stash list" + }, { + "title": "Show the contents of any stash in patch form", + "tip": "git stash show -p " + }, { + "title": "Apply any stash without deleting from the stashed list", + "tip": "git stash apply " + }, { + "title": "Apply last stashed state and delete it from stashed list", + "tip": "git stash pop", + "alternatives": ["git stash apply stash@{0} && git stash drop stash@{0}"] + }, { + "title": "Delete all stored stashes", + "tip": "git stash clear", + "alternatives": ["git stash drop "] + }, { + "title": "Grab a single file from a stash", + "tip": "git checkout -- ", + "alternatives": ["git checkout stash@{0} -- "] + }, { + "title": "Show all tracked files", + "tip": "git ls-files -t" + }, { + "title": "Show all untracked files", + "tip": "git ls-files --others" + }, { + "title": "Show all ignored files", + "tip": "git ls-files --others -i --exclude-standard" + }, { + "title": "Create new working tree from a repository (git 2.5)", + "tip": "git worktree add -b " + }, { + "title": "Create new working tree from HEAD state", + "tip": "git worktree add --detach HEAD" + }, { + "title": "Untrack files without deleting", + "tip": "git rm --cached ", + "alternatives": ["git rm --cached -r "] + }, { + "title": "Before deleting untracked files/directory, do a dry run to get the list of these files/directories", + "tip": "git clean -n" + }, { + "title": "Forcefully remove untracked files", + "tip": "git clean -f" + }, { + "title": "Forcefully remove untracked directory", + "tip": "git clean -f -d" + }, { + "title": "Update all the submodules", + "tip": "git submodule foreach git pull", + "alternatives": ["git submodule update --init --recursive", "git submodule update --remote"] + }, { + "title": "Show all commits in the current branch yet to be merged to master", + "tip": "git cherry -v master", + "alternatives": ["git cherry -v master "] + }, { + "title": "Rename a branch", + "tip": "git branch -m ", + "alternatives": ["git branch -m [] "] + }, { + "title": "Rebases 'feature' to 'master' and merges it in to master ", + "tip": "git rebase master feature && git checkout master && git merge -" + }, { + "title": "Archive the `master` branch", + "tip": "git archive master --format=zip --output=master.zip" + }, { + "title": "Modify previous commit without modifying the commit message", + "tip": "git add --all && git commit --amend --no-edit" + }, { + "title": "Prunes references to remove branches that have been deleted in the remote.", + "tip": "git fetch -p", + "alternatives": ["git remote prune origin"] + }, { + "title": "Delete local branches that has been squash and merged in the remote.", + "tip": "git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D" + }, { + "title": "Retrieve the commit hash of the initial revision.", + "tip": " git rev-list --reverse HEAD | head -1", + "alternatives": ["git rev-list --max-parents=0 HEAD", "git log --pretty=oneline | tail -1 | cut -c 1-40", "git log --pretty=oneline --reverse | head -1 | cut -c 1-40"] + }, { + "title": "Visualize the version tree.", + "tip": "git log --pretty=oneline --graph --decorate --all", + "alternatives": ["gitk --all", "git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d'"] + }, { + "title": "Visualize the tree including commits that are only referenced from reflogs", + "tip": "git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all)" + }, { + "title": "Deploying git tracked subfolder to gh-pages", + "tip": "git subtree push --prefix subfolder_name origin gh-pages", + "alternatives": "git subtree push --prefix subfolder_name origin branch_name" + }, { + "title": "Adding a project to repo using subtree", + "tip": "git subtree add --prefix=/ --squash git@github.com:/.git master" + }, { + "title": "Get latest changes in your repo for a linked project using subtree", + "tip": "git subtree pull --prefix=/ --squash git@github.com:/.git master" + }, { + "title": "Export a branch with history to a file.", + "tip": "git bundle create " + }, { + "title": "Import from a bundle", + "tip": "git clone repo.bundle -b " + }, { + "title": "Get the name of current branch.", + "tip": "git rev-parse --abbrev-ref HEAD" + }, { + "title": "Ignore one file on commit (e.g. Changelog).", + "tip": "git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog" + }, { + "title": "Stash changes before rebasing", + "tip": "git rebase --autostash" + }, { + "title": "Fetch pull request by ID to a local branch", + "tip": "git fetch origin pull//head:", + "alternatives": ["git pull origin pull//head:"] + }, { + "title": "Show the most recent tag on the current branch.", + "tip": "git describe --tags --abbrev=0" + }, { + "title": "Show inline word diff.", + "tip": "git diff --word-diff" + }, { + "title": "Show changes using common diff tools.", + "tip": "git difftool [-t ] " + }, { + "title": "Don’t consider changes for tracked file.", + "tip": "git update-index --assume-unchanged " + }, { + "title": "Undo assume-unchanged.", + "tip": "git update-index --no-assume-unchanged " + }, { + "title": "Clean the files from `.gitignore`.", + "tip": "git clean -X -f" + }, { + "title": "Restore deleted file.", + "tip": "git checkout -- " + }, { + "title": "Restore file to a specific commit-hash", + "tip": "git checkout -- " + }, { + "title": "Always rebase instead of merge on pull.", + "tip": "git config --global pull.rebase true", + "alternatives": ["#git < 1.7.9\ngit config --global branch.autosetuprebase always"] + }, { + "title": "List all the alias and configs.", + "tip": "git config --list" + }, { + "title": "Make git case sensitive.", + "tip": "git config --global core.ignorecase false" + }, { + "title": "Add custom editors.", + "tip": "git config --global core.editor '$EDITOR'" + }, { + "title": "Auto correct typos.", + "tip": "git config --global help.autocorrect 1" + }, { + "title": "Check if the change was a part of a release.", + "tip": "git name-rev --name-only " + }, { + "title": "Dry run. (any command that supports dry-run flag should do.)", + "tip": "git clean -fd --dry-run" + }, { + "title": "Marks your commit as a fix of a previous commit.", + "tip": "git commit --fixup " + }, { + "title": "Squash fixup commits normal commits.", + "tip": "git rebase -i --autosquash" + }, { + "title": "Skip staging area during commit.", + "tip": "git commit --only " + }, { + "title": "Interactive staging.", + "tip": "git add -i" + }, { + "title": "List ignored files.", + "tip": "git check-ignore *" + }, { + "title": "Status of ignored files.", + "tip": "git status --ignored" + }, { + "title": "Commits in Branch1 that are not in Branch2", + "tip": "git log Branch1 ^Branch2" + }, { + "title": "List n last commits", + "tip": "git log -", + "alternatives": ["git log -n "] + }, { + "title": "Reuse recorded resolution, record and reuse previous conflicts resolutions.", + "tip": "git config --global rerere.enabled 1" + }, { + "title": "Open all conflicted files in an editor.", + "tip": "git diff --name-only | uniq | xargs $EDITOR" + }, { + "title": "Count unpacked number of objects and their disk consumption.", + "tip": "git count-objects --human-readable" + }, { + "title": "Prune all unreachable objects from the object database.", + "tip": "git gc --prune=now --aggressive" + }, { + "title": "Instantly browse your working repository in gitweb.", + "tip": "git instaweb [--local] [--httpd=] [--port=] [--browser=]" + }, { + "title": "View the GPG signatures in the commit log", + "tip": "git log --show-signature" + }, { + "title": "Remove entry in the global config.", + "tip": "git config --global --unset " + }, { + "title": "Checkout a new branch without any history", + "tip": "git checkout --orphan " + }, { + "title": "Extract file from another branch.", + "tip": "git show :" + }, { + "title": "List only the root and merge commits.", + "tip": "git log --first-parent" + }, { + "title": "Change previous two commits with an interactive rebase.", + "tip": "git rebase --interactive HEAD~2" + }, { + "title": "List all branch is WIP", + "tip": "git checkout master && git branch --no-merged" + }, { + "title": "Find guilty with binary search", + "tip": "git bisect start # Search start \ngit bisect bad # Set point to bad commit \ngit bisect good v2.6.13-rc2 # Set point to good commit|tag \ngit bisect bad # Say current state is bad \ngit bisect good # Say current state is good \ngit bisect reset # Finish search \n" + }, { + "title": "Bypass pre-commit and commit-msg githooks", + "tip": "git commit --no-verify" + }, { + "title": "List commits and changes to a specific file (even through renaming)", + "tip": "git log --follow -p -- " + }, { + "title": "Clone a single branch", + "tip": "git clone -b --single-branch https://github.com/user/repo.git" + }, { + "title": "Create and switch new branch", + "tip": "git checkout -b ", + "alternatives": ["git branch && git checkout ", "git switch -c "] + }, { + "title": "Ignore file mode changes on commits", + "tip": "git config core.fileMode false" + }, { + "title": "Turn off git colored terminal output", + "tip": "git config --global color.ui false" + }, { + "title": "Specific color settings", + "tip": "git config --global " + }, { + "title": "Show all local branches ordered by recent commits", + "tip": "git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/" + }, { + "title": "Find lines matching the pattern (regex or string) in tracked files", + "tip": "git grep --heading --line-number 'foo bar'" + }, { + "title": "Clone a shallow copy of a repository", + "tip": "git clone https://github.com/user/repo.git --depth 1" + }, { + "title": "Search Commit log across all branches for given text", + "tip": "git log --all --grep=''" + }, { + "title": "Get first commit in a branch (from master)", + "tip": "git log --oneline master.. | tail -1", + "alternatives": ["git log --reverse master.. | head -6"] + }, { + "title": "Unstaging Staged file", + "tip": "git reset HEAD " + }, { + "title": "Force push to Remote Repository", + "tip": "git push -f " + }, { + "title": "Adding Remote name", + "tip": "git remote add " + }, { + "title": "List all currently configured remotes", + "tip": "git remote -v" + }, { + "title": "Show the author, time and last revision made to each line of a given file", + "tip": "git blame " + }, { + "title": "Group commits by authors and title", + "tip": "git shortlog" + }, { + "title": "Forced push but still ensure you don't overwrite other's work", + "tip": "git push --force-with-lease " + }, { + "title": "Show how many lines does an author contribute", + "tip": "git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | gawk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf \"added lines: %s removed lines: %s total lines: %s\n\", add, subs, loc }' -", + "alternatives": ["git log --author='_Your_Name_Here_' --pretty=tformat: --numstat | awk '{ add += $1; subs += $2; loc += $1 - $2 } END { printf \"added lines: %s, removed lines: %s, total lines: %s\n\", add, subs, loc }' - # on Mac OSX"] + }, { + "title": "Revert: Reverting an entire merge", + "tip": "git revert -m 1 " + }, { + "title": "Number of commits in a branch", + "tip": "git rev-list --count " + }, { + "title": "Alias: git undo", + "tip": "git config --global alias.undo '!f() { git reset --hard $(git rev-parse --abbrev-ref HEAD)@{${1-1}}; }; f'" + }, { + "title": "Add object notes", + "tip": "git notes add -m 'Note on the previous commit....'" + }, { + "title": "Show all the git-notes", + "tip": "git log --show-notes='*'" + }, { + "title": "Apply commit from another repository", + "tip": "git --git-dir=/.git format-patch -k -1 --stdout | git am -3 -k" + }, { + "title": "Specific fetch reference", + "tip": "git fetch origin master:refs/remotes/origin/mymaster" + }, { + "title": "Find common ancestor of two branches", + "tip": "git merge-base " + }, { + "title": "List unpushed git commits", + "tip": "git log --branches --not --remotes", + "alternatives": ["git log @{u}..", "git cherry -v"] + }, { + "title": "Add everything, but whitespace changes", + "tip": "git diff --ignore-all-space | git apply --cached" + }, { + "title": "Edit [local/global] git config", + "tip": "git config [--global] --edit" + }, { + "title": "blame on certain range", + "tip": "git blame -L ," + }, { + "title": "Show a Git logical variable.", + "tip": "git var -l | " + }, { + "title": "Preformatted patch file.", + "tip": "git format-patch -M upstream..topic" + }, { + "title": "Get the repo name.", + "tip": "git rev-parse --show-toplevel" + }, { + "title": "logs between date range", + "tip": "git log --since='FEB 1 2017' --until='FEB 14 2017'" + }, { + "title": "Exclude author from logs", + "tip": "git log --perl-regexp --author='^((?!excluded-author-regex).*)$'" + }, { + "title": "Generates a summary of pending changes", + "tip": "git request-pull v1.0 https://git.ko.xz/project master:for-linus" + }, { + "title": "List references in a remote repository", + "tip": "git ls-remote git://git.kernel.org/pub/scm/git/git.git" + }, { + "title": "Backup untracked files.", + "tip": "git ls-files --others -i --exclude-standard | xargs zip untracked.zip" + }, { + "title": "List all git aliases", + "tip": "git config -l | grep alias | sed 's/^alias\\.//g'", + "alternatives": ["git config -l | grep alias | cut -d '.' -f 2"] + }, { + "title": "Show git status short", + "tip": "git status --short --branch" + }, + { + "title": "Checkout a commit prior to a day ago", + "tip": "git checkout master@{yesterday}" + }, { + "title": "Push the current branch to the same name on the remote repository", + "tip": "git push origin HEAD" + }, { + "title": "Push a new local branch to remote repository and track", + "tip": "git push -u origin " + }, { + "title": "Change a branch base", + "tip": "git rebase --onto " + }, { + "title": "Use SSH instead of HTTPs for remotes", + "tip": "git config --global url.'git@github.com:'.insteadOf 'https://github.com/'" + }, { + "title": "Update a submodule to the latest commit", + "tip": "cd \ngit pull origin \ncd \ngit add \ngit commit -m \"submodule updated\"" + }, { + "title": "Prevent auto replacing LF with CRLF", + "tip": "git config --global core.autocrlf false" + } ]