This may be useful to rebuildĮverything from scratch, but keep manually created files.ĭon’t actually remove anything, just show what would be done. With git reset) to create a pristine working directory to test a clean This can be used (possibly in conjunction This allows removing all untracked files, gitignore (perĭirectory) and $GIT_DIR/info/exclude, but do still use the ignore If the Git configuration variable clean.requireForce is not set toįalse, git clean will refuse to run unless given -f, -n or -i.ĭon’t use the standard ignore rules read from. If clean.requireForce is set to "true" (the default) in your configuration, one needs to specify -f otherwise nothing will actually happen.Īgain see the git-clean docs for more information. Note the case difference on the X for the two latter commands. To remove ignored and non-ignored files, run git clean -f -x or git clean -fx.To remove ignored files, run git clean -f -X or git clean -fX.To remove directories, run git clean -f -d or git clean -fd.Step 1 is to show what will be deleted by using the -n option: # Print out the list of files and directories which will be removed (dry run)Ĭlean Step - beware: this will delete files: # Delete the files from the repository arguments are given, only those paths are affected. This can, for example, be useful to remove all build products. Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also removed. But any changes that are commits are recoverable even if you lose them, via the reflog, or via branch pointers or tags that you can set.Git-clean - Remove untracked files from the working tree Synopsis git clean …Ĭleans the working tree by recursively removing files that are not under version control, starting from the current directory. Type the wrong command that wipes out either or both of these and they are gone for good. The working copy and index are not commit objects and so they are not recoverable from the reflog. One reason to get your work into commits is that in git is very easy to lose the working copy or the index forever. In fact, if you have unstaged or staged changes, git prevents you from doing various useful things. The idea is to turn the representation of all your changes into separate commits, then work with the commit-munging kung-fu, and finally "de-commit" something, if necessary.įor doing complex things, git is better at working with commits than with unstaged changes or the index, which are sort of temporary areas so you want to get your work out of there and into commits first. Or else just keep the commit and work with it by doing more hacking and git commit -amend to add to it and update its message.Įverything that rebase -interactive does (and in fact, that non-interactive rebase does) can be done with cherry-pick commands, but it provides a convenient "workflow automation".įor any scenarios involving the re-ordering of commits, deletion of commits, squashing of multiple commits into one, rewriting commit messages (other than in the topmost patch) and that sort of thing, it's good to know how to use interactive rebase. At that point, I could get rid of that commit, turning it into unstaged changes: git reset HEAD^ There might be merge conflicts, which would have to be resolved, since the previously unstaged wanted changes might have depended on the staged unwanted changes.Īt the end, I would have a single commit which has just the changes that were previously unstaged, and the unwanted changes are gone. In the editor window that comes up, I would simply delete the commit which holds the unwanted changes that came from the unwanted index, and then save and quit, letting the interactive rebase do the rest. Git rebase -interactive HEAD^^ # rebase top two commits onto same branch Git commit -a # commit the remaining changes In that case, what I would do would be to use interactive rebase to splice the changes out: git commit # commit the index The end effect is exactly like squirreling away the results of git diff HEAD, rolling everything back to the topmost commit, and then re-applying that diff to HEAD to re-create the original work tree.īut suppose you want to throw away the changes from the index such that these discarded changes are actually subtracted from your work. This is equivalent to your self answer, "using git commands only". To discard the index without touching the working tree, you can just do this: git reset
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |