So, you are at a point where you know you need to do some cleanup in your git repo, potentially using rebase or other stuff that could make it really messy to undo if you do it wrong.
Is there a way to tell Git "save this state of the entire local git repo, so that I can rollback everything to this point, in case things go wrong?" Something like a "sandbox mode", which lets you play around with your repo safely, performing potentialy disasterous operations, without the risk of messing anything up.
I'm not talking about adding a tag or something to a specific point in history, but about something that would reset all the changes made in the git repo on all branches from that particular state in time. The potential to roll back everything (all the git history/state). Something similar to the OSX Time Machine.
Update 2019-02-19: I should clarify that by "potentially disasterous operations", I don't mean to the code itself, but actually messing around with the repo structure in git, using for instance git reset --hard
or similar commands.
Sandbox Git Repository Git is a version control system that we use to track changes to our source code and documentation. You can find a sandbox Git repository where you can practice the Git commands before you put together a patch to resolve a bug or implement a new functionality.
A sandbox is a local copy of a project's files, used to make changes and test work. Each developer should work from her own sandbox on a computer that is convenient to her. The CVS repository contains the master copies of a project's files and their full histories.
Committing to organizationsClick on the CodeSandbox application and you will be taken to the settings. In here you can check what organizations CodeSandbox has access to and grant it access to the organization you want to deploy to. After this you will be able to commit from CodeSandbox to that organization.
The Git repository itself is a sandbox.
Clone your repository and play in the cloned repo. You can do anything in it, you can even completely destroy it (remove it). As long as you don't git push
, the original remains untouched.
If you want to start over just remove the clone and re-create it again. Or run:
git checkout master
git reset --hard origin/master
The checkout
command makes master
the current branch on the local repo. The reset
command restores the local current branch and the working tree to the state of branch master
on the origin
remote (assuming you started playing on the master
branch).
You can just copy your folder with Git repository somewhere else and do anything you want there (assuming only local operations). This will not affect your original local repo and if you want to discard changes in your copy - just remove it and copy again.
Git tries very hard to not lose or corrupt data and already provides tools to help you recover work. Its basic build blocks are persistent immutable data structures.
For example, instead of rebasing branch foo
directly, create a new branch named foo/rebase
where foo
currently is, check it out and rebase foo/rebase
instead. You will see that none of the commits reachable from foo
will be modified, so you are safe to work on the new branch. Just like a transaction, you can rollback the work (simply remove foo/rebase
) or commit that operation (make foo
points to foo/rebase
with reset --hard
, or maybe merge).
In any case, you still have the reflog which keeps references to objects not currently reachable by any branch or tag. You could also clone your repository, but this is a bit overkill in most situations. In your case it seems that you are going to change branches in mass, so I must admit that cloning the repository might be the best approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With