![]() ![]() ![]() ![]() ![]() I'm using the -D flag for git branch, which is an alias for -delete -force.There are two things to look out for here: To provide a list of branches that begin with a number, I can run this command: $ git branch | grep "^\ \d" For example, I often precede branches with a number when they are addressing a specific issue. Having a pattern for how you name branches can come in handy when cleaning up like this. For example, to see a list of all branches, excluding the current branch, you could run this command: $ git branch | grep "^" It can come in handy to give the first two commands a whirl so you know what you're going to delete. xargs gives us the returned list from grep, and then we pass those to git branch -D, which deletes the branch.grep searches the list and returns those lines that match the pattern.It precedes the current branch with an asterisk. The command looks like this: $ git branch | grep | xargs git branch -D All you need is some regular expression pattern to target the branch names, and then you sweep through them. To verify, I checked out to another branch, and voila - no hiding commit to fetch/pull from the master.Ever get yourself caught in a situation where you have a whole mess of branches and you want to get cleaned up? Git rebase -i then d, drop = remove commit. Ah.glossed over new feature troll the n00b in the 2.8.3 release notes. " If you remove a line here THAT COMMIT WILL BE LOST". poof! the commit was back - Git wins.Ĭhecking back out to master, time to try git rebase -i, then remove the line. To get the most recent SHA, I checked the remote repository on - minor win.Īfter thinking git reset -hard had worked, I updated another branch to master and 1. Git reset -hard HEAD did nothing, after checking the reflog, the last and only HEAD was the clone - Git wins. I didn't wish to git revert - it would create an additional commit, giving Git the upper hand. Now it had re-added a most recent unneeded commit to master I wished to remove, so proceeded like so. Exiting with no changes, I charged my battery then proceeded to shave, as all 900 individual commits nonchalantly rebased - resetting their commit times to now.ĭetermined to beat Git and preserve the original times, I deleted this local repository and re-cloned from the remote. I grew a Silicon Valley beard while 900 commits loaded themselves into Sublime. I git rebase -i -root'ed my branch, ignorantly thinking I could reword the first commit differing from the master (the GitHub for Windows default view is the comparison to master, hiding it's entirety). Lastly, if you need to find a commit that you "deleted", it is typically present in git reflog unless you have garbage collected your repository. It will reset you back to the most recent commit, and erase all the changes in your working tree and index. However, both commits will be in the log.įYI: git reset -hard HEAD is great if you want to get rid of WORK IN PROGRESS. If you already pushed, it may be better to use git revert, to create a "mirror image" commit that will undo the changes. Because when they pull, it will just merge it into their work, and you will get it pushed back up again. However, if others may have pulled it, then you would be better off starting a new branch. If you already pushed it, you will need to do a force push to get rid of it. Or, you could look at the output of git log, find the commit id of the commit you want to back up to, and then do this: git reset -hard Careful: git reset -hard WILL DELETE YOUR WORKING DIRECTORY CHANGES.īe sure to stash any local changes you want to keep before running this command.Īssuming you are sitting on that commit, then this command will wack it. ![]()
0 Comments
Leave a Reply. |