4 ms·
I'm actually somewhat surprised that this wasn't mentioned in the comments yet: https://ohshitgit.com/ https://ohshitgit.com/ Which is a page that covers common
by godot 7y ago
I'm actually somewhat surprised that this wasn't mentioned in the comments yet: https://ohshitgit.com/ https://ohshitgit.com/ Which is a page that covers common mistakes using git and quick ways to fix your mistakes. I've found myself making a mistake mentioned on this page with regularity and always refer to the site to help myself fix it quickly.
(It looks like they have a swearing-safe version now at https://dangitgit.com/ https://dangitgit.com/)
- Stratoscope 7y agoIf you have to use the command line, those "gosh darn it git" sites have some good recipes. Because if the problem is "I accidentally committed to the wrong branch!" who is going to remember all this off the top of their head: # undo the last commit, but leave the changes available git reset HEAD~ --soft git stash # move to the correct branch git checkout name-of-the-correct-branch git stash pop git add . # or add individual files git commit -m "your message here"; # now your changes are on the correct branch Or you can use a powerful GUI like SmartGit. Then you don't have to memorize anything or look up a recipe. For the situation above, you simply drag your branch markers to where you want them in the log. Done! Similarly, for situations where you would look up hashes in the reflog, just click the Recyclable Commits checkbox, and everything in the reflog shows up as ordinary commits in the same commit tree as everything else. You can even see diffs between the reflog commits and your regular commits without having to do any temporary checkouts. I know many developers like the command line and don't want to consider using a GUI. But I encourage you to give SmartGit a try. It works in conjunction with the command line, so you you're not locked into the GUI, you can use either one whenever you want.
- maksimum 7y ago> It works in conjunction with the command line Do you know of git GUIs that explicitly maintain a bijection between the GUI and the underlying command history? It'd be cool to use the GUI and see the command history, or use the CLI and see updates in the GUI.
- Stratoscope 7y agoI'm not sure if this is exactly what you're looking for, but maybe close? SmartGit has an Output window that shows the underlying Git commands that it uses when you drag things around or use its commands. And if you make changes in the command line and then switch back to the SmartGit window, it updates to match.
- Jestar342 7y agoGit-fork does this.
- _pmf_ 7y ago> use the CLI and see updates in the GUI Which GUI tool does not?
- mike_hock 7y agoI know you're trying to sell your SyntEvo(R) SmartGit(TM), but the last thing I'd want while already trying to recover from a mistake is having a third party tool do some opaque magic on the repo, in the same way that I wouldn't just copy-paste a recipe without understanding how it works. OTOH if a common operation can be performed reliably I'd much rather it be upstreamed.
- Stratoscope 7y ago> I know you're trying to sell your SyntEvo(R) [sic] SmartGit(TM) That is a remarkably uncharitable comment. If you have any evidence that I am a shill for syntevo, and not just a happy customer, you should state it. Otherwise you owe me an apology.
- _pmf_ 7y agoI'm also a non-shill advocating SmartGit at any opportunity. Is it so incomprehensible for FOSS users that there are commercial products that are so great that they have a dedicated fan base s opposed to half baked open source crap?
- mrcarrot 7y agoEverything apart from the initial reset command in that ‘recipe’ is stuff that a command line git user would be doing all the time anyway. There’s not really anything to remember here, other than that ‘git reset’ lets me undo commits that I haven’t pushed.
- jnurmine 7y agoThere are other ways to do that, too. For example, Git stash is my blind spot and I don't really use it. A conceptually simple way (for me) is to: checkout "good" branch, cherry-pick the "wrong" commit, then checkout the "bad" branch and remove the "wrong" commit ("git reset --hard HEAD^"). Mixing and matching simple commands mechanistically means everything can in fact be remembered. YMMV.
- Doxin 7y agoYou might want to try using rebase for this use case too, Saves a couple checkout steps. Just make sure to specify the right commit range ;)
- Doxin 7y agoIf you're trying to memorize that list of commands without understanding what is happening under the hood you have a snowflakes chance in hell. If on the other hand you've read (and understood!) the git reset manpage it's hardly magic. Git reset changes the ref HEAD is pointing at. So in this case HEAD is pointing to the branch you've accidentally committed to. Running `git reset HEAD- --soft` simply moves the branch to point to one commit previous. The soft flag tells git reset to not touch any actual files while doing this, so your changes stay untouched. This is really the most complex part. After this all that's happening is re-committing the same changes to the correct branch. The git stash is even optional if the changes don't conflict with any changes done by the checkout. You're right, memorizing a list of commands like that is a fools errand. What's not a fools errand is understanding the underlying data structure of git and how various commands act on it. Which is all documented in the official docs by the way, using a writing style that's rather readable in my opinion. Switching to a GUI wholesale is throwing out the baby with the bathwater. Using a GUI tool still requires knowing how git works to be effective. Of course you might still argue that it's too much typing, which is probably true. Good thing git aliases got invented so even though I can recall the entire command list you mentioned from memory I'd still in practice simply run "git uncommit" since I've had that alias defined for about forever now. This comment isn't aimed at anyone in particular and especially not at the parent comment. The parent comment just hit my grumpy button I think ;-)