There are several problems with such a notion:
Not all operations are reversible. Sometimes this is because Git doesn't record enough information to deduce the prior state - that'd be prohibitively expensive in general. Sometimes it's things like git reset --hard
or git clean
, which destroy untracked changes. In order to undo them, it'd have to be continuously automatically backing up. Sometimes this is because the notion of undo is ambiguous - as you yourself pointed out, there are many ways to undo a commit.
If an operation is reversible, and it involved some sort of history, should the undo/redo also be in the history, or should they make it vanish? Should a commit be undone by resetting back, or by reverting (creating another commit to cancel it)?
Without logging every last thing you do, how would you know what the most recent operation was? Say you added a file to the index, and created a branch. There's no record of which was first.
Even if everything were clearly defined, it'd be an absurd amount of work to implement. How do you decide what constitutes a single action? A single Git command might do many things. Should it undo one step, the whole thing? What if you've run a zillion commands each doing a tiny step and you want to undo it all? And it'd have to be perfect, completely perfect, because it's the kind of feature that will be used by inexperienced users who'll have no idea how to recover from any mistake.
So, just as Git gives you the tools to do things, it gives you the tools to see what you've done, and undo things yourself if so desired.
Also, with respect to "redo", as you defined it in your question, it's repeating a command, not doing the original operation again. When you redid a commit, it was a different one. Re-running a previous command is something that command-line shells were designed to do. Git doesn't need to reinvent it.
git rebase
. Check this gitready.com/intermediate/2009/01/31/intro-to-rebase.html – Recourse