diff --git a/.doxie.render.js b/.doxie.render.js deleted file mode 100644 index 82673fa..0000000 --- a/.doxie.render.js +++ /dev/null @@ -1,24 +0,0 @@ -function escapeStr(str) { - return str - .replace(/\"/g, '\\"') - .replace(/\n/g, '\\n'); -} - -var render = function(data) { - var data = data.data; - - var tips = [ - '## ' + data.title, - '```sh', - data.tip, - '```', - '\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 deleted file mode 100644 index bc74e84..0000000 --- a/.doxie.render.toc.js +++ /dev/null @@ -1,19 +0,0 @@ -// 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 + '](#' + slugify(data.title) + ')\n'; - - return out; -}; - -module.exports = render; diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml new file mode 100644 index 0000000..c0c620f --- /dev/null +++ b/.github/workflows/deploy-docs.yml @@ -0,0 +1,30 @@ +name: Deploy GitBook + +on: + push: + branches: + - master + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install Dependencies + run: npm ci + + - name: Build Docs + run: npm run docs:build + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/_book diff --git a/.github/workflows/update-readme.yml b/.github/workflows/update-readme.yml new file mode 100644 index 0000000..e4e335a --- /dev/null +++ b/.github/workflows/update-readme.yml @@ -0,0 +1,40 @@ +name: Update README + +on: + push: + branches: + - master + paths: + - 'tips.json' + +jobs: + update-readme: + runs-on: ubuntu-latest + steps: + - name: Checkout Repository + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install Dependencies + run: npm ci + + - name: Generate README + run: node build-readme.js + + - name: Check for changes + id: diff + run: | + git diff --quiet README.md docs/ || echo "changed=true" >> $GITHUB_OUTPUT + + - name: Commit and push updated README + if: steps.diff.outputs.changed == 'true' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add README.md docs/ + git commit -m "docs: auto-generate README and docs from tips.json [skip ci]" + git push diff --git a/.gitignore b/.gitignore index 67d713f..b848f5c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea node_modules npm-debug.log +docs/_book 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/README.md b/README.md index 8681c13..ec5c99a 100644 --- a/README.md +++ b/README.md @@ -1,1166 +1,1488 @@ ## 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) +[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)) +📖 **[Read the interactive GitBook documentation here!](https://git-tips.github.io/tips/)** + P.S: All these commands are tested on `git version 2.7.4 (Apple Git-66)`. - - -* [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) -* [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) -* [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) -* [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) -* [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 remote branches that have been deleted in the remote.](#prunes-references-to-remote-branches-that-have-been-deleted-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) -* [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) -* [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 a new local branch to remote repository and track](#push-a-new-local-branch-to-remote-repository-and-track) - - - - - - - -## Everyday Git in twenty commands or so +## Table of Contents + +* [Basic Operations](#basic-operations) + * [List of all files till a commit](#list-of-all-files-till-a-commit) + * [Quickly switch to the previous branch](#quickly-switch-to-the-previous-branch) + * [Delete remote branch](#delete-remote-branch) + * [Delete remote tag](#delete-remote-tag) + * [Undo local changes with the content in index(staging)](#undo-local-changes-with-the-content-in-indexstaging) + * [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) + * [Stage parts of a changed file, instead of the entire file](#stage-parts-of-a-changed-file-instead-of-the-entire-file) + * [Pick commits across branches using cherry-pick](#pick-commits-across-branches-using-cherry-pick) + * [Grab a single file from a stash](#grab-a-single-file-from-a-stash) + * [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) + * [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) + * [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) + * [Retrieve the commit hash of the initial revision.](#retrieve-the-commit-hash-of-the-initial-revision) + * [Import from a bundle](#import-from-a-bundle) + * [Ignore one file on commit (e.g. Changelog).](#ignore-one-file-on-commit-eg-changelog) + * [Fetch pull request by ID to a local branch](#fetch-pull-request-by-id-to-a-local-branch) + * [Restore deleted file.](#restore-deleted-file) + * [Restore file to a specific commit-hash](#restore-file-to-a-specific-commit-hash) + * [Marks your commit as a fix of a previous commit.](#marks-your-commit-as-a-fix-of-a-previous-commit) + * [Skip staging area during commit.](#skip-staging-area-during-commit) + * [Interactive staging.](#interactive-staging) + * [Status of ignored files.](#status-of-ignored-files) + * [Checkout a new branch without any history](#checkout-a-new-branch-without-any-history) + * [Find guilty with binary search](#find-guilty-with-binary-search) + * [Bypass pre-commit and commit-msg githooks](#bypass-pre-commit-and-commit-msg-githooks) + * [Clone a single branch](#clone-a-single-branch) + * [Create and switch new branch](#create-and-switch-new-branch) + * [Show all local branches ordered by recent commits](#show-all-local-branches-ordered-by-recent-commits) + * [Clone a shallow copy of a repository](#clone-a-shallow-copy-of-a-repository) + * [Force push to Remote Repository](#force-push-to-remote-repository) + * [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) + * [Number of commits in a branch](#number-of-commits-in-a-branch) + * [Add object notes](#add-object-notes) + * [Apply commit from another repository](#apply-commit-from-another-repository) + * [Specific fetch reference](#specific-fetch-reference) + * [Generates a summary of pending changes](#generates-a-summary-of-pending-changes) + * [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) + * [Update a submodule to the latest commit](#update-a-submodule-to-the-latest-commit) + * [Duplicating a repository](#duplicating-a-repository) + * [Sparse checkout: clone only specific directories](#sparse-checkout-clone-only-specific-directories) + * [Show output in columns](#show-output-in-columns) + * [List worktrees](#list-worktrees) + * [Remove a worktree](#remove-a-worktree) +* [Branching](#branching) + * [List all branches that are already merged into master](#list-all-branches-that-are-already-merged-into-master) + * [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) + * [Get list of all local and remote branches](#get-list-of-all-local-and-remote-branches) + * [Get only remote branches](#get-only-remote-branches) + * [Find out branches containing commit-hash](#find-out-branches-containing-commit-hash) + * [Rename a branch](#rename-a-branch) + * [Archive the `master` branch](#archive-the-master-branch) + * [Delete local branches that has been squash and merged in the remote.](#delete-local-branches-that-has-been-squash-and-merged-in-the-remote) + * [Export a branch with history to a file.](#export-a-branch-with-history-to-a-file) + * [Get the name of current branch.](#get-the-name-of-current-branch) + * [Show the most recent tag on the current branch.](#show-the-most-recent-tag-on-the-current-branch) + * [List all branch is WIP](#list-all-branch-is-wip) + * [Preformatted patch file.](#preformatted-patch-file) + * [Switch to a branch (modern alternative to checkout)](#switch-to-a-branch-modern-alternative-to-checkout) +* [Log and History](#log-and-history) + * [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) + * [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) + * [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) + * [Show all tracked files](#show-all-tracked-files) + * [Show all untracked files](#show-all-untracked-files) + * [Show all ignored files](#show-all-ignored-files) + * [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) + * [Show inline word diff.](#show-inline-word-diff) + * [Show changes using common diff tools.](#show-changes-using-common-diff-tools) + * [Commits in Branch1 that are not in Branch2](#commits-in-branch1-that-are-not-in-branch2) + * [List n last commits](#list-n-last-commits) + * [Open all conflicted files in an editor.](#open-all-conflicted-files-in-an-editor) + * [View the GPG signatures in the commit log](#view-the-gpg-signatures-in-the-commit-log) + * [Extract file from another branch.](#extract-file-from-another-branch) + * [List only the root and merge commits.](#list-only-the-root-and-merge-commits) + * [List commits and changes to a specific file (even through renaming)](#list-commits-and-changes-to-a-specific-file-even-through-renaming) + * [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) + * [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) + * [Show how many lines does an author contribute](#show-how-many-lines-does-an-author-contribute) + * [Show all the git-notes](#show-all-the-git-notes) + * [List unpushed git commits](#list-unpushed-git-commits) + * [Add everything, but whitespace changes](#add-everything-but-whitespace-changes) + * [blame on certain range](#blame-on-certain-range) + * [Show a Git logical variable.](#show-a-git-logical-variable) + * [Get the repo name.](#get-the-repo-name) + * [logs between date range](#logs-between-date-range) + * [Exclude author from logs](#exclude-author-from-logs) + * [View expanded details of changes in last commit](#view-expanded-details-of-changes-in-last-commit) + * [Visualize each position of HEAD in the last 30 days](#visualize-each-position-of-head-in-the-last-30-days) + * [Compare two versions of a rebased branch](#compare-two-versions-of-a-rebased-branch) + * [Automate bisect with a test script](#automate-bisect-with-a-test-script) + * [Blame with line range](#blame-with-line-range) + * [Detect moved or copied lines in blame](#detect-moved-or-copied-lines-in-blame) + * [Log with graph in oneline format](#log-with-graph-in-oneline-format) + * [Find commits where a file was deleted](#find-commits-where-a-file-was-deleted) + * [Show commit count per author per time period](#show-commit-count-per-author-per-time-period) + * [Verify commit signatures](#verify-commit-signatures) + * [Show diff with word-level granularity using color](#show-diff-with-word-level-granularity-using-color) +* [Merging and Rebasing](#merging-and-rebasing) + * [Rebases 'feature' to 'master' and merges it in to master ](#rebases-feature-to-master-and-merges-it-in-to-master-) + * [Stash changes before rebasing](#stash-changes-before-rebasing) + * [Squash fixup commits normal commits.](#squash-fixup-commits-normal-commits) + * [Change previous two commits with an interactive rebase.](#change-previous-two-commits-with-an-interactive-rebase) + * [Find common ancestor of two branches](#find-common-ancestor-of-two-branches) + * [Change a branch base](#change-a-branch-base) + * [Create a fixup commit and auto-squash](#create-a-fixup-commit-and-auto-squash) + * [Rebase interactively from the root commit](#rebase-interactively-from-the-root-commit) +* [Miscellaneous](#miscellaneous) + * [Everyday Git in twenty commands or so](#everyday-git-in-twenty-commands-or-so) + * [Untrack files without deleting](#untrack-files-without-deleting) + * [Don’t consider changes for tracked file.](#dont-consider-changes-for-tracked-file) + * [Check if the change was a part of a release.](#check-if-the-change-was-a-part-of-a-release) + * [List ignored files.](#list-ignored-files) + * [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) + * [Find lines matching the pattern (regex or string) in tracked files](#find-lines-matching-the-pattern-regex-or-string-in-tracked-files) + * [Backup untracked files.](#backup-untracked-files) + * [Send a collection of patches as emails](#send-a-collection-of-patches-as-emails) +* [Remotes](#remotes) + * [Changing a remote's URL](#changing-a-remotes-url) + * [Get list of all remote references](#get-list-of-all-remote-references) + * [Adding Remote name](#adding-remote-name) + * [List all currently configured remotes](#list-all-currently-configured-remotes) + * [List references in a remote repository](#list-references-in-a-remote-repository) + * [Refresh the list of remote branches](#refresh-the-list-of-remote-branches) + * [Create a bundle file for offline sharing](#create-a-bundle-file-for-offline-sharing) + * [Clone from a bundle file](#clone-from-a-bundle-file) + * [Partial clone: clone without blobs for faster fetch](#partial-clone-clone-without-blobs-for-faster-fetch) +* [Setup and Config](#setup-and-config) + * [Remove sensitive data from history, after a push](#remove-sensitive-data-from-history-after-a-push) + * [Reset author, after author has been changed in the global config.](#reset-author-after-author-has-been-changed-in-the-global-config) + * [Get git bash completion](#get-git-bash-completion) + * [Git Aliases](#git-aliases) + * [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) + * [Reuse recorded resolution, record and reuse previous conflicts resolutions.](#reuse-recorded-resolution-record-and-reuse-previous-conflicts-resolutions) + * [Remove entry in the global config.](#remove-entry-in-the-global-config) + * [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) + * [Alias: git undo](#alias-git-undo) + * [Edit [local/global] git config](#edit-localglobal-git-config) + * [List all git aliases](#list-all-git-aliases) + * [Use SSH instead of HTTPs for remotes](#use-ssh-instead-of-https-for-remotes) + * [Prevent auto replacing LF with CRLF](#prevent-auto-replacing-lf-with-crlf) + * [Edit config for each level](#edit-config-for-each-level) + * [Enable background maintenance for faster operations](#enable-background-maintenance-for-faster-operations) + * [Sign commits with SSH key instead of GPG](#sign-commits-with-ssh-key-instead-of-gpg) + * [Enable rerere to auto-resolve recurring merge conflicts](#enable-rerere-to-auto-resolve-recurring-merge-conflicts) + * [Set default branch name for new repos](#set-default-branch-name-for-new-repos) +* [Stashing](#stashing) + * [Saving current state of tracked files without committing](#saving-current-state-of-tracked-files-without-committing) + * [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) + * [Stash only unstaged changes](#stash-only-unstaged-changes) + * [Stash specific files](#stash-specific-files) + * [Show a diffstat summary of a stash](#show-a-diffstat-summary-of-a-stash) +* [Submodules and Subtrees](#submodules-and-subtrees) + * [Update all the submodules](#update-all-the-submodules) + * [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) +* [Tagging](#tagging) + * [Create local tag](#create-local-tag) + * [Delete local tag](#delete-local-tag) +* [Undoing Changes](#undoing-changes) + * [Sync with remote, overwrite local changes](#sync-with-remote-overwrite-local-changes) + * [Git reset first commit](#git-reset-first-commit) + * [Reset: preserve uncommitted local changes](#reset-preserve-uncommitted-local-changes) + * [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) + * [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) + * [Undo assume-unchanged.](#undo-assume-unchanged) + * [Clean the files from `.gitignore`.](#clean-the-files-from-gitignore) + * [Dry run. (any command that supports dry-run flag should do.)](#dry-run-any-command-that-supports-dry-run-flag-should-do) + * [Unstaging Staged file](#unstaging-staged-file) + * [Revert: Reverting an entire merge](#revert-reverting-an-entire-merge) + * [Restore file (modern alternative to reset/checkout --)](#restore-file-modern-alternative-to-resetcheckout---) + +## Basic Operations + +### List of all files till a commit ```sh -git help everyday +git ls-tree --name-only -r ``` -## Show helpful guides that come with Git +### Quickly switch to the previous branch ```sh -git help -g +git checkout - +``` +**Alternatives:** +```sh +git checkout @{-1} ``` -## Search change by content +### Delete remote branch ```sh -git log -S'' +git push origin --delete +``` +**Alternatives:** +```sh +git push origin : +``` +```sh +git branch -dr ``` -## Remove sensitive data from history, after a push +### Delete remote tag ```sh -git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch ' --prune-empty --tag-name-filter cat -- --all && git push origin --force --all +git push origin :refs/tags/ ``` -## Sync with remote, overwrite local changes +### Undo local changes with the content in index(staging) ```sh -git fetch origin && git reset --hard origin/master && git clean -f -d +git checkout -- +``` +**Alternatives:** +```sh +git restore ``` -## List of all files till a commit +### Reword the previous commit message ```sh -git ls-tree --name-only -r +git commit -v --amend ``` -## Git reset first commit +### See commit history for just the current branch ```sh -git update-ref -d HEAD +git cherry -v master ``` -## List all the conflicted files +### Amend author. ```sh -git diff --name-only --diff-filter=U +git commit --amend --author='Author Name ' ``` -## List of all files changed in a commit +### Stage parts of a changed file, instead of the entire file ```sh -git diff-tree --no-commit-id --name-only -r +git add -p ``` -## Unstaged changes since last commit +### Pick commits across branches using cherry-pick ```sh -git diff +git checkout && git cherry-pick ``` -## Changes staged for commit +### Grab a single file from a stash ```sh -git diff --cached +git checkout -- +``` +**Alternatives:** +```sh +git checkout stash@{0} -- ``` +### Create new working tree from a repository (git 2.5) +```sh +git worktree add -b +``` -__Alternatives:__ +### Create new working tree from HEAD state ```sh -git diff --staged +git worktree add --detach HEAD ``` -## Show both staged and unstaged changes +### Show all commits in the current branch yet to be merged to master ```sh -git diff HEAD +git cherry -v master +``` +**Alternatives:** +```sh +git cherry -v master ``` -## List all branches that are already merged into master +### Modify previous commit without modifying the commit message ```sh -git branch --merged master +git add --all && git commit --amend --no-edit ``` -## Quickly switch to the previous branch +### Prunes references to remove branches that have been deleted in the remote. ```sh -git checkout - +git fetch -p +``` +**Alternatives:** +```sh +git remote prune origin ``` +### 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 +``` -__Alternatives:__ +### Import from a bundle ```sh -git checkout @{-1} +git clone repo.bundle -b ``` -## Remove branches that have already been merged with master +### Ignore one file on commit (e.g. Changelog). ```sh -git branch --merged master | grep -v '^\*' | xargs -n 1 git branch -d +git update-index --assume-unchanged Changelog; git commit -a; git update-index --no-assume-unchanged Changelog ``` +### Fetch pull request by ID to a local branch +```sh +git fetch origin pull//head: +``` +**Alternatives:** +```sh +git pull origin pull//head: +``` -__Alternatives:__ +### Restore deleted file. ```sh -git branch --merged master | grep -v '^\*\| master' | xargs -n 1 git branch -d # will not delete master if master is not checked out +git checkout -- ``` -## List all branches and their upstreams, as well as last commit on branch +### Restore file to a specific commit-hash ```sh -git branch -vv +git checkout -- ``` -## Track upstream branch +### Marks your commit as a fix of a previous commit. ```sh -git branch -u origin/mybranch +git commit --fixup ``` -## Delete local branch +### Skip staging area during commit. ```sh -git branch -d +git commit --only ``` -## Delete remote branch +### Interactive staging. ```sh -git push origin --delete +git add -i ``` +### Status of ignored files. +```sh +git status --ignored +``` -__Alternatives:__ +### Checkout a new branch without any history ```sh -git push origin : +git checkout --orphan ``` -## Delete local tag +### Find guilty with binary search ```sh -git tag -d +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 + ``` -## Delete remote tag +### Bypass pre-commit and commit-msg githooks ```sh -git push origin :refs/tags/ +git commit --no-verify ``` -## Undo local changes with the last content in head +### Clone a single branch ```sh -git checkout -- +git clone -b --single-branch https://github.com/user/repo.git ``` -## Revert: Undo a commit by creating a new commit +### Create and switch new branch ```sh -git revert +git checkout -b +``` +**Alternatives:** +```sh +git branch && git checkout +``` +```sh +git switch -c ``` -## Reset: Discard commits, advised for private branch +### Show all local branches ordered by recent commits ```sh -git reset +git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ ``` -## Reword the previous commit message +### Clone a shallow copy of a repository ```sh -git commit -v --amend +git clone https://github.com/user/repo.git --depth 1 ``` -## See commit history for just the current branch +### Force push to Remote Repository ```sh -git cherry -v master +git push -f ``` -## Amend author. +### Group commits by authors and title ```sh -git commit --amend --author='Author Name ' +git shortlog ``` -## Reset author, after author has been changed in the global config. +### Forced push but still ensure you don't overwrite other's work ```sh -git commit --amend --reset-author --no-edit +git push --force-with-lease ``` -## Changing a remote's URL +### Number of commits in a branch ```sh -git remote set-url origin +git rev-list --count ``` -## Get list of all remote references +### Add object notes ```sh -git remote +git notes add -m 'Note on the previous commit....' +``` + +### 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 +``` -__Alternatives:__ +### Generates a summary of pending changes ```sh -git remote show +git request-pull v1.0 https://git.ko.xz/project master:for-linus +``` + +### Show git status short +```sh +git status --short --branch ``` -## Get list of all local and remote branches +### 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 +``` + +### Update a submodule to the latest commit +```sh +cd +git pull origin +cd +git add +git commit -m "submodule updated" +``` + +### Duplicating a repository +```sh +git clone --bare https://github.com/exampleuser/old-repository.git + +git push --mirror https://github.com/exampleuser/new-repository.git +``` + +### Sparse checkout: clone only specific directories +```sh +git clone --filter=blob:none --sparse && cd && git sparse-checkout set +``` + +### Show output in columns +```sh +git branch --column +``` +**Alternatives:** +```sh +git tag --column +``` + +### List worktrees +```sh +git worktree list +``` + +### Remove a worktree +```sh +git worktree remove +``` +**Alternatives:** +```sh +git worktree prune +``` + +## Branching + +### List all branches that are already merged into master +```sh +git branch --merged master +``` + +### Remove branches that have already been merged with master +```sh +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 +```sh +git branch -vv +``` + +### Track upstream branch +```sh +git branch -u origin/mybranch +``` + +### Delete local branch +```sh +git branch -d +``` + +### Get list of all local and remote branches ```sh git branch -a ``` -## Get only remote branches +### Get only remote branches ```sh git branch -r ``` -## Stage parts of a changed file, instead of the entire file +### Find out branches containing commit-hash ```sh -git add -p +git branch -a --contains +``` +**Alternatives:** +```sh +git branch --contains ``` -## Get git bash completion +### Rename a branch +```sh +git branch -m +``` +**Alternatives:** ```sh -curl http://git.io/vfhol > ~/.git-completion.bash && echo '[ -f ~/.git-completion.bash ] && . ~/.git-completion.bash' >> ~/.bashrc +git branch -m [] ``` -## What changed since two weeks? +### Archive the `master` branch ```sh -git log --no-merges --raw --since='2 weeks ago' +git archive master --format=zip --output=master.zip ``` +### Delete local branches that has been squash and merged in the remote. +```sh +git branch -vv | grep ': gone]' | awk '{print $1}' | xargs git branch -D +``` -__Alternatives:__ +### Export a branch with history to a file. ```sh -git whatchanged --since='2 weeks ago' +git bundle create ``` -## See all commits made since forking from master +### Get the name of current branch. ```sh -git log --no-merges --stat --reverse master.. +git rev-parse --abbrev-ref HEAD ``` -## Pick commits across branches using cherry-pick +### Show the most recent tag on the current branch. ```sh -git checkout && git cherry-pick +git describe --tags --abbrev=0 ``` -## Find out branches containing commit-hash +### List all branch is WIP ```sh -git branch -a --contains +git checkout master && git branch --no-merged ``` +### Preformatted patch file. +```sh +git format-patch -M upstream..topic +``` -__Alternatives:__ +### Switch to a branch (modern alternative to checkout) ```sh -git branch --contains +git switch +``` +**Alternatives:** +```sh +git switch -c ``` -## Git Aliases +## Log and History + +### Show helpful guides that come with Git ```sh -git config --global alias. -git config --global alias.st status +git help -g ``` -## Saving current state of tracked files without commiting +### Search change by content ```sh -git stash +git log -S'' ``` +### Show changes over time for specific file +```sh +git log -p +``` -__Alternatives:__ +### List all the conflicted files ```sh -git stash save +git diff --name-only --diff-filter=U ``` -## Saving current state of unstaged changes to tracked files +### List of all files changed in a commit ```sh -git stash -k +git diff-tree --no-commit-id --name-only -r ``` +### Unstaged changes since last commit +```sh +git diff +``` -__Alternatives:__ +### Changes staged for commit ```sh -git stash --keep-index +git diff --cached +``` +**Alternatives:** +```sh +git diff --staged ``` +### Show both staged and unstaged changes +```sh +git diff HEAD +``` +### What changed since two weeks? ```sh -git stash save --keep-index +git log --no-merges --raw --since='2 weeks ago' +``` +**Alternatives:** +```sh +git whatchanged --since='2 weeks ago' ``` -## Saving current state including untracked files +### See all commits made since forking from master ```sh -git stash -u +git log --no-merges --stat --reverse master.. ``` +### Show all tracked files +```sh +git ls-files -t +``` -__Alternatives:__ +### Show all untracked files ```sh -git stash save -u +git ls-files --others ``` +### Show all ignored files +```sh +git ls-files --others -i --exclude-standard +``` +### Visualize the version tree. ```sh -git stash save --include-untracked +git log --pretty=oneline --graph --decorate --all +``` +**Alternatives:** +```sh +gitk --all +``` +```sh +git log --graph --pretty=format:'%C(auto) %h | %s | %an | %ar%d' ``` -## Saving current state with message +### Visualize the tree including commits that are only referenced from reflogs ```sh -git stash save +git log --graph --decorate --oneline $(git rev-list --walk-reflogs --all) ``` -## Saving current state of all files (ignored, untracked, and tracked) +### Show inline word diff. ```sh -git stash -a +git diff --word-diff ``` +### Show changes using common diff tools. +```sh +git difftool [-t ] +``` -__Alternatives:__ +### Commits in Branch1 that are not in Branch2 ```sh -git stash --all +git log Branch1 ^Branch2 ``` +### List n last commits +```sh +git log - +``` +**Alternatives:** +```sh +git log -n +``` +### Open all conflicted files in an editor. ```sh -git stash save --all +git diff --name-only | uniq | xargs $EDITOR ``` -## Show list of all saved stashes +### View the GPG signatures in the commit log ```sh -git stash list +git log --show-signature ``` -## Apply any stash without deleting from the stashed list +### Extract file from another branch. ```sh -git stash apply +git show : ``` -## Apply last stashed state and delete it from stashed list +### List only the root and merge commits. ```sh -git stash pop +git log --first-parent ``` +### List commits and changes to a specific file (even through renaming) +```sh +git log --follow -p -- +``` -__Alternatives:__ +### Search Commit log across all branches for given text ```sh -git stash apply stash@{0} && git stash drop stash@{0} +git log --all --grep='' ``` -## Delete all stored stashes +### Get first commit in a branch (from master) ```sh -git stash clear +git log --oneline master.. | tail -1 +``` +**Alternatives:** +```sh +git log --reverse master.. | head -6 +``` + +### Show the author, time and last revision made to each line of a given file +```sh +git blame ``` +### Show how many lines does an author contribute +```sh +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 +", add, subs, loc }' - +``` +**Alternatives:** +```sh +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 +", add, subs, loc }' - # on Mac OSX +``` + +### Show all the git-notes +```sh +git log --show-notes='*' +``` + +### 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 +``` + +### blame on certain range +```sh +git blame -L , +``` + +### Show a Git logical variable. +```sh +git var -l | +``` + +### Get the repo name. +```sh +git rev-parse --show-toplevel +``` -__Alternatives:__ +### logs between date range ```sh -git stash drop +git log --since='FEB 1 2017' --until='FEB 14 2017' ``` -## Grab a single file from a stash +### Exclude author from logs ```sh -git checkout -- +git log --perl-regexp --author='^((?!excluded-author-regex).*)$' ``` - -__Alternatives:__ +### View expanded details of changes in last commit ```sh -git checkout stash@{0} -- +git show ``` -## Show all tracked files +### Visualize each position of HEAD in the last 30 days ```sh -git ls-files -t +git reflog ``` -## Show all untracked files +### Compare two versions of a rebased branch ```sh -git ls-files --others +git range-diff .. .. ``` - -## Show all ignored files +**Alternatives:** ```sh -git ls-files --others -i --exclude-standard +git range-diff ... ``` -## Create new working tree from a repository (git 2.5) +### Automate bisect with a test script ```sh -git worktree add -b +git bisect start && git bisect run