{"id":28529,"date":"2018-04-27T13:14:24","date_gmt":"2018-04-27T11:14:24","guid":{"rendered":"https:\/\/mamchenkov.net\/wordpress\/?p=28529"},"modified":"2018-04-27T13:14:24","modified_gmt":"2018-04-27T11:14:24","slug":"git-clean-a-nice-addition-to-git-reset","status":"publish","type":"post","link":"https:\/\/mamchenkov.net\/wordpress\/2018\/04\/27\/git-clean-a-nice-addition-to-git-reset\/","title":{"rendered":"git clean &#8211; a nice addition to git reset"},"content":{"rendered":"<!-- google_ad_section_start -->\n<p>Anybody working with git is probably well familiar with the way to undo the non-committed changes:<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">\r\ngit reset --hard\r\n<\/pre>\n<p>As useful as the above command is, it still leaves some room for improvement. The above command will only undo non-committed changes on the files that git is tracking. Often, this would leave a whole bunch of files and directories in place, which are not tracked by git. So far, I&#8217;ve been using a really complicated approach for removing them, which involves git status, grep, cut, xargs, and rm. Yuck.<\/p>\n<p>Turns out there is a better way, which I found in &#8220;<a href=\"http:\/\/webchick.net\/stupid-git-tricks\">Stupid git tricks<\/a>&#8221; article:<\/p>\n<pre class=\"brush: bash; light: true; title: ; notranslate\" title=\"\">\r\ngit clean -df .\r\n<\/pre>\n<p>This one will forcefully remove all untracked files and directories from the current directory. Combining these two commands together results in all non-committed changes being undone, no matter if they are on tracked files or not. Cool!<\/p>\n<!-- google_ad_section_end -->\n","protected":false},"excerpt":{"rendered":"<!-- google_ad_section_start -->\n<p>Anybody working with git is probably well familiar with the way to undo the non-committed changes: git reset &#8211;hard As useful as the above command is, it still leaves some room for improvement. The above command will only undo non-committed changes on the files that git is tracking. Often, this would leave a whole bunch &hellip; <a href=\"https:\/\/mamchenkov.net\/wordpress\/2018\/04\/27\/git-clean-a-nice-addition-to-git-reset\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">git clean &#8211; a nice addition to git reset<\/span><\/a><\/p>\n<!-- google_ad_section_end -->\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"git clean - a nice addition to git reset #WebDev #git #VersionControl #CLI","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"_links_to":"","_links_to_target":""},"categories":[1,6,18,133,62],"tags":[1960,2265,1588,1330],"keyring_services":[],"class_list":["post-28529","post","type-post","status-publish","format-standard","hentry","category-general","category-linux","category-programming","category-sysadmin","category-technology","tag-command-line","tag-git","tag-version-control","tag-web-development"],"aioseo_notices":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":26685,"url":"https:\/\/mamchenkov.net\/wordpress\/2016\/09\/12\/git-history-of-a-source-code-line\/","url_meta":{"origin":28529,"position":0},"title":"git: history of a source code line","author":"Leonid Mamchenkov","date":"September 12, 2016","format":false,"excerpt":"git is one of those tools that no matter how much you know about it, there is an infinite supply of new things to learn. \u00a0Here's a handy bit I've discovered recently, thanks to this StackOverflow comment: Since Git 1.8.4, git log has -L to view the evolution of a\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27374,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/02\/27\/moving-files-with-commit-history-from-one-git-repository-to-another\/","url_meta":{"origin":28529,"position":1},"title":"Moving files with commit history from one git repository to another","author":"Leonid Mamchenkov","date":"February 27, 2017","format":false,"excerpt":"I've searched for this before, and I'm sure I'll do that again (although the need is not that frequent), so here it goes. \u00a0It is possible to move files from one git repository to another, preserving commit history. \u00a0The following links provide a few examples of how to do this:\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":21877,"url":"https:\/\/mamchenkov.net\/wordpress\/2014\/05\/29\/gitjk-undo-what-you-just-did-in-git\/","url_meta":{"origin":28529,"position":2},"title":"gitjk &#8211; undo what you just did in git","author":"Leonid Mamchenkov","date":"May 29, 2014","format":"link","excerpt":"gitjk - undo what you just did in git. Supports the following git commands: add, archive, branch, cat-file, checkout, clone, commit, diff, fetch, grep, init, log, ls-tree, merge, mv, pull, push, remote, revert, rm, show, stash,status. Support for the following git commands is not implemented: bisect, fsck, gc, prune, rebase,\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":27398,"url":"https:\/\/mamchenkov.net\/wordpress\/2017\/03\/08\/how-to-use-git-to-manage-your-user-configuration-files\/","url_meta":{"origin":28529,"position":3},"title":"How To Use Git to Manage your User Configuration Files","author":"Leonid Mamchenkov","date":"March 8, 2017","format":false,"excerpt":"There is probably a gadzillion different ways that you can manage and synchronize you configuration files (aka dotfiles) between different Linux\/UNIX boxes - anything from custom symlink scripts, all the way to configuration management tools like Puppet and Ansible. \u00a0Here are a few options to look at if you are\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":17655,"url":"https:\/\/mamchenkov.net\/wordpress\/2013\/01\/09\/git-separating-folder-into-different-repository-with-history\/","url_meta":{"origin":28529,"position":4},"title":"Git : separating folder into different repository, with history","author":"Leonid Mamchenkov","date":"January 9, 2013","format":false,"excerpt":"First things first. \u00a0If you don't use git for version control yet, stop right now and go plan your migration. \u00a0You'll thank me later. \u00a0Now. \u00a0A few days ago I had a tricky problem. \u00a0A chunk of code that was initially all over the project has been refactored into a\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":24322,"url":"https:\/\/mamchenkov.net\/wordpress\/2015\/06\/09\/git-undo\/","url_meta":{"origin":28529,"position":5},"title":"git undo","author":"Leonid Mamchenkov","date":"June 9, 2015","format":false,"excerpt":"The GitHub Blog runs a very handy post:\u00a0How to undo (almost) anything with Git, which covers a variety of git scenarios which you'd want to undo - anything from typos in commit messages to handling of branches. If you don't feel like learning all that, have a look at gitjk\u2026","rel":"","context":"In &quot;All&quot;","block_context":{"text":"All","link":"https:\/\/mamchenkov.net\/wordpress\/category\/general\/"},"img":{"alt_text":"git","src":"https:\/\/i0.wp.com\/mamchenkov.net\/wordpress\/wp-content\/uploads\/2015\/06\/git-500x117.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/28529","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/comments?post=28529"}],"version-history":[{"count":0,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/posts\/28529\/revisions"}],"wp:attachment":[{"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/media?parent=28529"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/categories?post=28529"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/tags?post=28529"},{"taxonomy":"keyring_services","embeddable":true,"href":"https:\/\/mamchenkov.net\/wordpress\/wp-json\/wp\/v2\/keyring_services?post=28529"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}