{"id":19484533,"url":"https://github.com/flowerinthenight/git-cheatsheet","last_synced_at":"2026-06-11T13:31:42.485Z","repository":{"id":73334380,"uuid":"86019357","full_name":"flowerinthenight/git-cheatsheet","owner":"flowerinthenight","description":"My commonly used commands in git.","archived":false,"fork":false,"pushed_at":"2017-06-20T05:44:35.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-08T07:44:38.535Z","etag":null,"topics":["git"],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flowerinthenight.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2017-03-24T02:37:30.000Z","updated_at":"2017-03-24T02:48:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"3b262d6e-3595-49e6-b151-1166f588be9b","html_url":"https://github.com/flowerinthenight/git-cheatsheet","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/flowerinthenight%2Fgit-cheatsheet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fgit-cheatsheet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fgit-cheatsheet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flowerinthenight%2Fgit-cheatsheet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flowerinthenight","download_url":"https://codeload.github.com/flowerinthenight/git-cheatsheet/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240720837,"owners_count":19846828,"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-11-10T20:22:29.018Z","updated_at":"2025-02-25T18:25:00.364Z","avatar_url":"https://github.com/flowerinthenight.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Personal GIT cheatsheet\n\n### Reset a file\n\n```\ngit checkout HEAD -- my-file.txt\n```\n\n### Delete last commit\n\n```\ngit reset --hard HEAD~1\n```\n\n### Delete local branch\n\n```\ngit branch -d \u003cbranch-name\u003e\n```\n\nor force delete with\n\n```\ngit branch -D \u003cbranch-name\u003e\n```\n\n### Delete branch from remote repository\n\n```\ngit push origin --delete \u003cremote-branch-name\u003e\n```\n\n### Search for the merge commit from a specific commit\n\n```\ngit log \u003cSHA\u003e..master --ancestry-path --merges\n```\n\n### Search for a commit message\n\n```\ngit log | grep \u003cpattern\u003e\n```\n\n### List commits on range line of codes for one file\n\n```\ngit blame -L\u003cline#\u003e,+\u003coffset\u003e -- \u003cfilename\u003e\n```\n\nFor example, three lines starting from line 257 of main.cpp\n\n```\ngit blame -L257,+3 -- main.cpp\n```\n\n### History of a line (or lines) in a file\n\n```\ngit log --topo-order --graph -u -L \u003cline-start\u003e,\u003cline-end\u003e:\u003cfile\u003e\n```\n\nFor example, history of line 155 of main.cpp\n\n```\ngit log --topo-order --graph -u -L 155,155:main.cpp\n```\n\n### Compare (diff) a file from the current branch to another branch\n\n```\ngit diff ..\u003ctarget-branch\u003e \u003cpath-to-file\u003e\n```\n\nor if difftool is configured\n\n```\ngit difftool ..\u003ctarget-branch\u003e \u003cpath-to-file\u003e\n```\n\n### Rebase/squash all branch commits\n\n```\ngit checkout -b new-branch\nmodify...\ncommit...\n...\ngit rebase -i master\n(sometimes, I branch out of master for a clean branch and do a git rebase -i clean-branch)\n```\n\n### Combine all branch commits to one before merging to master (sort of like the one above)\n\n```\ngit checkout master\ngit checkout -b clean\ngit merge --squash branch_to_merge_to_one_commit\ngit commit\n(add commit message)\ngit checkout master\ngit merge clean\n```\n\n### Revert a file or directory to a previous commit\n\n```\ngit checkout \u003ccommit_id\u003e -- file/or/directory\n```\n\n### Custom format for log\n\nAdd to global `.gitconfig` using `git config --global alias.logp \"...\"`\n\n```\ngit log --pretty=format:'%Cred%h %C(yellow)%d%Creset %s %Cgreen(%cr|%ci) %C(bold blue)[%an]%Creset'\n```\n\n# License\n\n[The MIT License](./LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowerinthenight%2Fgit-cheatsheet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflowerinthenight%2Fgit-cheatsheet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflowerinthenight%2Fgit-cheatsheet/lists"}