{"id":16822815,"url":"https://github.com/dentarg/git","last_synced_at":"2025-03-18T00:47:53.855Z","repository":{"id":66645248,"uuid":"13921069","full_name":"dentarg/git","owner":"dentarg","description":":hammer: Handy git commands","archived":false,"fork":false,"pushed_at":"2021-04-14T08:39:40.000Z","size":16,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-24T09:08:36.536Z","etag":null,"topics":["git"],"latest_commit_sha":null,"homepage":"https://pinboard.in/u:dentarg/t:git","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dentarg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-10-28T09:07:56.000Z","updated_at":"2021-04-14T08:39:42.000Z","dependencies_parsed_at":"2023-03-31T12:36:58.622Z","dependency_job_id":null,"html_url":"https://github.com/dentarg/git","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dentarg%2Fgit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dentarg%2Fgit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dentarg%2Fgit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dentarg%2Fgit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dentarg","download_url":"https://codeload.github.com/dentarg/git/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244135897,"owners_count":20403797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["git"],"created_at":"2024-10-13T11:05:58.777Z","updated_at":"2025-03-18T00:47:53.832Z","avatar_url":"https://github.com/dentarg.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"git\n===\n\n### How to modify a specified commit?\n\nIf you want to edit `\u003csha\u003e`:\n\n    git rebase -i \u003csha\u003e^\n    # change \"pick\" to \"edit\" for \u003csha\u003e, save\n    # \u003cdo edits\u003e\n    git add ...\n    git commit -v --amend --no-edit # uses same commit message as before\n    git rebase --continue\n\nsrc: https://stackoverflow.com/questions/1186535/how-to-modify-a-specified-commit\n\n### Ignore whitespace when comparing lines\n\n    git diff -w\n\nsrc: https://git-scm.com/docs/git-diff#git-diff--w\n\n### Change commit messages of past commits\n\n    git rebase -i \u003ccommit before the first you want to edit\u003e\n\nReplace \"pick\" with \"reword\" for the commits you want to edit the message of. `$EDITOR` will open automatically until there's no more commit messages to edit.\n\nsrc: [Change old commit message on Git](http://stackoverflow.com/questions/1884474/change-old-commit-message-on-git), [Change commit messages of past Git commits](http://makandracards.com/makandra/868-change-commit-messages-of-past-git-commits)\n\n### Change tag annotation message\n\n    # Fixing tag named '1.0.1'\n    git checkout 1.0.1               # Go to the associated commit\n    git tag -d 1.0.1                 # Locally delete the tag\n    git push origin :refs/tags/1.0.1 # Push this deletion up to GitHub\n\n    # Create the tag, with a date derived from the current head\n    GIT_COMMITTER_DATE=\"$(git show --format=%aD | head -1)\" git tag -a 1.0.1 -m\"v1.0.1\"\n\n    git push --tags                  # Send the fixed tags to GitHub\n\nsrc: [How do I edit an existing tag message in git?](http://stackoverflow.com/a/29019547/525616), [Change date of git tag (or GitHub Release based on it)](http://stackoverflow.com/a/21741848/525616)\n\n### Open commit from command line (with [`hub`](http://hub.github.com/))\n\n    hub browse -- commit/46109ccf\n    \nsrc: [hub browse: improve support for opening a commit](https://github.com/github/hub/issues/516)\n\n### Open pull request from command line (with [`hub`](http://hub.github.com/))\n\n    git co -b newstuff\n    git ci -m 'Add new stuff'\n    git push -u origin newstuff\n    hub pull-request\n\n#### Convert existing issue to a pull request:\n\n    hub pull-request -i \u003cissue number\u003e\n\nNote: You need to be the creator of the issue.\n\nsrc: [How do you attach a new pull request to an existing issue on github?](http://stackoverflow.com/questions/4528869/how-do-you-attach-a-new-pull-request-to-an-existing-issue-on-github)\n\n### Merge pull request from command line (with `hub`)\n\n    git co master\n    hub merge https://github.com/user/zambezi/pull/11\n    git push\n\nsrc: [man hub](http://hub.github.com/hub.1.html)\n\n### Undo last commit and keep the changes\n\n    git reset --soft HEAD^\n\nsrc: [Git Delete Last Commit](http://nakkaya.com/2009/09/24/git-delete-last-commit/)\n\n### Undo N last commits and keep the changes\n\nN=3:\n\n    git reset --soft HEAD~3\n\nsrc: [Squash my last X commits together using Git](http://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git/5201642#5201642)\n\n### Delete the last commit (does NOT keep the changes)\n\n    git reset --hard HEAD^\n\nsrc: [Git Delete Last Commit](http://nakkaya.com/2009/09/24/git-delete-last-commit/)\n\n### Start a git commit message with a hashmark (`#`)\n\n    git commit --cleanup=whitespace\n\nsrc: [Start a git commit message with a hashmark (`#`)](http://stackoverflow.com/questions/2788092/start-a-git-commit-message-with-a-hashmark)\n\n### Patches\n\nCreate patch file for a commit\n\n    $ git format-patch -1 c460a1a324571b30ef2a6f4373be053c1ead2066\n    0001-Push-arbitrary-branch-to-origin-master.patch\n\nCheck if you can apply the patch\n\n    $ git apply --check 0001-Push-arbitrary-branch-to-origin-master.patch\n\nApply the diff, but don't commit\n\n    $ git apply 0001-Push-arbitrary-branch-to-origin-master.patch\n\nApply the diff and make a commit\n\n    $ git am \u003c 0001-Push-arbitrary-branch-to-origin-master.patch\n\nIf someone else wrote the patch\n\n    $ git am --signoff \u003c 0001-Push-arbitrary-branch-to-origin-master.patch\n\nCan be handy to be able to ignore whitespace\n\n    $ git apply --ignore-space-change --ignore-whitespace \u003c 0001-Push-arbitrary-branch-to-origin-master.patch\n\nsrc: [How to create and apply a patch with Git](https://ariejan.net/2009/10/26/how-to-create-and-apply-a-patch-with-git/), [git: patch does not apply](http://stackoverflow.com/questions/4770177/git-patch-does-not-apply)\n\n### Push arbitrary branch to origin/master\n\n    git push origin my-feature-branch:master\n\nUseful when working with i.e. Heroku where the master branch gets deployed on push.\n\n### Reset master to origin/master\n\n    git co master\n\n    # optional backup\n    git branch previous_master\n\n    git reset --hard origin/master\n\nsrc: [How to reset master to origin/master?](http://superuser.com/questions/273172/how-to-reset-master-to-origin-master)\n\n### Search in history\n\n    git log -p -S search_string\n\nsrc: [git-log(1) Manual Page](http://git-scm.com/docs/git-log)\n\n### Selective `git stash`\n\n\u003e You can use git stash save --keep-index when you want to make two or more commits out of the changes in the work tree, and you want to test each change\nbefore committing:\n\n    # ... hack hack hack ...\n    $ git add --patch foo            # add just first part to the index\n    $ git stash save --keep-index    # save all other changes to the stash\n    $ edit/build/test first part\n    $ git commit -m 'First part'     # commit fully tested change\n    $ git stash pop                  # prepare to work on all other changes\n    # ... repeat above five steps until one commit remains ...\n    $ edit/build/test remaining parts\n    $ git commit foo -m 'Remaining parts'\n\nsrc: [`git-stash(1)`](http://git-scm.com/docs/git-stash)\n\n### Tracking Branches\n\n    git co -t origin/\u003cnew_branch\u003e\n\nExample:\n\n    $ git branch -a\n    * master\n      remotes/origin/coolbranch\n      remotes/origin/master\n    $ git co -t origin/coolbranch\n    $ git branch -a\n      master\n    * coolbranch\n      remotes/origin/coolbranch\n      remotes/origin/master\n\nsrc: [Tracking Branches](http://git-scm.com/book/en/Git-Branching-Remote-Branches#Tracking-Branches), [`git-checkout(1)`](http://git-scm.com/docs/git-checkout)\n\n### Remove remote branch\n\n    git push origin :branchname\n\nsrc: [push and delete remote branches](http://gitready.com/beginner/2009/02/02/push-and-delete-branches.html)\n\n### Remove remote tag\n\n    git tag -d mytag\n    git push origin :refs/tags/mytag\n\nsrc: [How to: Delete a remote Git tag](https://nathanhoad.net/how-to-delete-a-remote-git-tag)\n\n### Remove stale tracking branches\n\n    git remote prune origin\n\n`--dry-run` is handy if you're unsure what's going to happen:\n\n    git remote prune --dry-run origin\n\nsrc: [How do you Remove an Invalid Remote Branch Reference from Git?](http://stackoverflow.com/questions/1072171/how-do-you-remove-an-invalid-remote-branch-reference-from-git)\n\n### Remove untracked files\n\nDry run, show what would be done:\n\n    git clean -n\n\nRemove untracked directories in addition to untracked files:\n\n    git clean -d\n\nsrc: [`git-clean`](https://git-scm.com/docs/git-clean)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdentarg%2Fgit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdentarg%2Fgit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdentarg%2Fgit/lists"}