News for hackers. Stuff that matters.
Re:Git undo: We can do better by pizza234 on Monday June 21, 2021 @11:50AM (#27580353)
Are you using Git via GUI(s)?

Between my colleagues, there is a strong correlation between using a GUI, and messing up the repository.

I agree that Git's UX is pretty bad (checkout overloading; overlapping between checkout and reset; push overloading... yikes!), however, I believe that in contexts where using Git is a constraint, stop using GUIs is the best strategy one can apply to improve the understanding.

Re:Git undo: We can do better by smilekzs on Monday June 21, 2021 @01:06PM (#27581117)
I disagree.

First of all, a well-designed Git GUI (examples below) exposes the git's underlying data model to you; in contrast, the CLI obscures it until something breaks and you're forced into it without context. Git operates on a graph and there is simply no way around it. The more you're exposed to the graph, the better you can mentally model it and ask it to do the right things.

While there are many half-baked Electron-based UIs that only unnecessarily complicates things, there are good ones too:

On Windows (and Linux thru Mono), I use GitExtensions. The visualizations are sane and discover-friendly. It will tell you what to expect.

When I work on C++ projects, the one built into CLion (JetBrains family; as mentioned by a sibling comment) is very good on its own. What impresses me the most is that has good visual support of a patch-oriented workflow. You can work with multiple "changelists" offline, shuffle individual changes around, seamlessly convert between changelists and patch files, and (most importantly) still work nice with the vanilla git model as the "actual history". It also works transparently with conceptually monorepo projects that have multiple physical repos, allowing you to do simultaneous commits.

I feel VSCode, GitHub client, Kraken, and several other Electron-based stuff, are too focused on the "polish" than substance, or are too opinionated to be used across repos I don't own.

Re:Git undo: We can do better by jonnycomputer on Monday June 21, 2021 @04:31PM (#27584048)
So back when I was learning git, I was very shy about using any GUI because I was afraid that it would make learning how git works that much harder. I think that I somehow felt that the CLI was more fundamental, in some way. But I think you are right, and I was wrong. A better interface that puts the graph front and center would have led me to learn it so much faster, especially when it also exposes the command line equivalents, as magit does (or so I've heard).
Re:Git undo: We can do better by cerved on Monday June 21, 2021 @02:11PM (#27581916)
The CLI doesn't obscure as much as presupposes that you understand internal workings of git.

All GUIs are not created equal. The JetBRains GUIs are pretty good. Others try and impose git "their way" and just invite creating a mess.

Re:Git undo: We can do better by faizshah on Monday June 21, 2021 @07:22PM (#27585858)
Yep I love the git GUI in Jetbrains IDEs, especially the change lists and shelf based workflow. I also like using the IDE’s diff to quickly use parts of an old shelved patch or when I’m working through a book I can diff my project with the answer repo to quickly see and work through the differences. But my favorite feature is Local History which has saved me from many overzealous git disasters: https://www.jetbrains.com/help/webstorm/local-history.html

Basically the IDE has its own revision history of your project’s files that it stores and you can recover your files from it. So when you accidentally revert instead of undo or use —-hard when you didn’t really mean to, Local History comes and saves the day.

Re:Git undo: We can do better by gitgitgit on Monday June 21, 2021 @12:04PM (#27580484)
I use Git via the GitHub Desktop client (https://desktop.github.com) and find it _very easy_ to use Git without issue by following a simple rule: don't be clever. I have branches, I commit, I squash merge via a Pull Request. No rebasing, no moving commits around. There might be workflows where rebasing etc. are important and certainly in those cases, using a GUI is probably not a great idea -- but it's certainly possible to use a GUI without issue if you keep your workflow simple.
Re:Git undo: We can do better by phkahler on Monday June 21, 2021 @12:22PM (#27580704)
I squash locally, but learning to do that required learning vim. Fortunately vimtutor. Then my distro changed the default text editor launched from git... fortunately I knew enough to get by with that one - which might be emacs but I haven't verified.

Git is really weird but useful.

Re:Git undo: We can do better by sethd on Monday June 21, 2021 @12:35PM (#27580828)
Git will use whatever editor you have defined in $EDITOR. You can also define this specifically for Git via global config (~/.gitconfig) if you don't want it to use your session's $EDITOR variable:

    [core]
       editor = vim
Re:Git undo: We can do better by gbear0 on Monday June 21, 2021 @01:12PM (#27581198)
The default editor is usually configurable (of course you'd have to learn all the different contexts you can do this from first to know this is a thing ... discoverability is hard).

For example in ubuntu you can do

  sudo update-alternatives --config editor
Some programs will use the environment variable $EDITOR, so you can add this to your shell startup configs

  export EDITOR=vi
Or specifically for git cli you can run

  git config --global core.editor vi
Re:Git undo: We can do better by dec0dedab0de on Monday June 21, 2021 @12:01PM (#27580459)
I use the Pycharm/Jetbrains Git GUI. At this point I can't imagine effectively handling merge conflicts any other way.

EDIT: Also, I really like being able to look at a diff of every file before I commit, and easily choosing which files to include in a commit. Too often I see people on the CLI accidentally committing changes they didn't mean to, because there is no easy way to check everything at the last minute.

Re:Git undo: We can do better by tcoff91 on Monday June 21, 2021 @12:04PM (#27580492)
even if you use the git CLI you can still set up a mergetool so that when you are resolving merge conflicts you can use something like BeyondCompare or P4Merge to handle the merge conflicts.
Re:Git undo: We can do better by Hamuko on Monday June 21, 2021 @12:08PM (#27580560)
And every Xcode installation on macOS comes with FileMerge.app.
Re:Git undo: We can do better by mixmastamyk on Monday June 21, 2021 @01:36PM (#27581496)
Meld
Re:Git undo: We can do better by fiddlerwoaroof on Monday June 21, 2021 @12:29PM (#27580767)
There’s a really easy way to check the diff before committing on the command-line:

    git commit -v
Displays a diff at the bottom of the editor that pops up to write a commit message.
Re:Git undo: We can do better by cerved on Tuesday June 22, 2021 @03:40AM (#27589008)
you can also set

  git config commit.verbose true
to always have this behavior
Re:Git undo: We can do better by Ashanmaril on Monday June 21, 2021 @01:40PM (#27581537)
The Jetbrains IDE git GUI is by far the best git GUI I've used, I feel lost trying to use git without it.

There's a user request that's been sitting around for a while to pull it out into a dedicated application, which I could personally get behind since we have one project at work that's pretty difficult to run outside of Eclipse

https://youtrack.jetbrains.com/issue/IDEA-152437

Re:Git undo: We can do better by tailspin2019 on Monday June 21, 2021 @05:35PM (#27584831)
Yes Jetbrains have totally nailed this. I have tended to prefer the command line for git but the exceptionally designed GUI support in Rider is fast changing that - especially for rebasing.
Re:Git undo: We can do better by stevenhuang on Monday June 21, 2021 @02:28PM (#27582152)
What's wrong with 'git diff'?

Then there's 'git add -i' to easily choose which files to add

Re:Git undo: We can do better by dividedbyzero on Tuesday June 22, 2021 @07:00AM (#27590138)
> What's wrong with 'git diff'?

Not GP, but I find it extremely hard to parse visually even after having had to do it a lot. Something like git-delta makes it bearable, but a decent syntax-highlighted, color-coded, side-by-side diff view with proper keyboard navigation (next diff, next file) is a huge quality of life boost for me.

> Then there's 'git add -i' to easily choose which files to add

Didn't know that, just tried it, and, wow, that's easily the most unintuitive and inscrutable TUI since vi. I haven't been able to make it show a simple diff; someone else also tried, failed as well.

Re:Git undo: We can do better by cerved on Tuesday June 22, 2021 @03:38AM (#27588999)
it's very easy from the CLI. Much easier than from GUIs actually

  git diff
  git diff --staged
  git restore --staged --partial
  git commit
you can also add commit hooks to reject changes like conflict markers
Re:Git undo: We can do better by zubspace on Monday June 21, 2021 @12:38PM (#27580851)
I'm a huge fan of git fork [1] on windows (or mac). Looks good, never failed me and does everything I need (branching, rebasing, merging, squashing, cherry picking, blaming and it can even show lost commits with reflog). And it performs really well (in contrary to sourcetree).

[1] https://git-fork.com/

Re:Git undo: We can do better by dividedbyzero on Tuesday June 22, 2021 @07:06AM (#27590176)
This looks neat! And a one-time purchase, too.
Re:Git undo: We can do better by woah on Monday June 21, 2021 @01:31PM (#27581443)
Sorry, I'm trying to get work done, not memorize an obscure set of incantations like some kind of D&D wizard. If the repo gets messed up, I delete it and reclone.
Re:Git undo: We can do better by Shacklz on Monday June 21, 2021 @05:38PM (#27584865)
I really understand your sentiment, and I've been there for long enough myself - but once you have a somewhat decent understanding about gits internal data model, the commands that allow you to clean up pretty much any mess (reset & reflog probably being the most prominent ones) start to somewhat make sense. If you had previous exposure to anything computer-science, it very likely won't take more than a few hours until the puzzle pieces start to come together.

And it's time well-spent in my opinion; git will probably be one of the longer-lasting constants in software development.

Re:Git undo: We can do better by pjmlp on Tuesday June 22, 2021 @02:16AM (#27588575)
> And it's time well-spent in my opinion; git will probably be one of the longer-lasting constants in software development.

Unfortunely.

Re:Git undo: We can do better by cerved on Monday June 21, 2021 @02:17PM (#27581986)
It's a handful of commands, very well documented with tons of SO questions that is one search away if you can figure it out yourself.

It's something I use all day, every day. I'd say it's worthwhile to learn if your daily job involves working under source control

Re:Git undo: We can do better by tailspin2019 on Monday June 21, 2021 @05:39PM (#27584878)
Yes I agree. If you’re going to use git (whether by choice or force) it is 100% worth learning the small set of commands required to undo a screwup without needing to reclone.

Recloning to me is a bit like tearing your house down and rebuilding it just because you painted your living room the wrong colour (in most cases!)

Re:Git undo: We can do better by cerved on Tuesday June 22, 2021 @03:42AM (#27589022)
at least if you are a carpenter
Re:Git undo: We can do better by clappski on Tuesday June 22, 2021 @06:34AM (#27589976)
Isn't understanding how to use your tools part of being effective at getting work done?

Sure, recloning and cp your changes to a fresh local repo will _work_, but what happens on the day you don't have access to the remote? What happens when you have to work on a repo that takes minutes to clone from the remote? All of those lost minutes because you don't understand how to use your tools means you aren't getting work done.

> memorize an obscure set of incantations like some kind of D&D wizard

If you're using Git then you're probably someone that works on software, isn't our whole job memorizing and reproducing permutations of obscure incantations to produce business value? Knowing how to use your tools provides business value, that's not some hot take but literally how you provide value to whoever pays you.

Re:Git undo: We can do better by overgard on Monday June 21, 2021 @12:53PM (#27580999)
I find GUI's to be very helpful; most of my commits happen through VSCode's commit panel. For my home Unity3D project I use sourcetree because my commits unfortunately end up being to a lot of unrelated files (blame unity), and having a UI to stage them saves a lot of typing. I avoid anything like rebasing (never got the point of that), but I use branches liberally. I find with this setup, I only need to use a handful of command line options, and I haven't screwed up a local repository in a long time.
Re:Git undo: We can do better by muststopmyths on Monday June 21, 2021 @01:12PM (#27581193)
If you are on Windows, Visual Studio's GUI is actually quite good for staging, merging and diffing. I tend to use it for most of those simpler kinds of things while still doing commits, rebase etc. from the command line.

Same for VSCode on non-Windows.

I only mention this because I came to hate Sourcetree in its newer iterations on Windows so much that I tried out Visual Studio's support and was pleasantly surprised.

Re:Git undo: We can do better by PufPufPuf on Monday June 21, 2021 @02:44PM (#27582441)
Funnily, I use a GUI almost exclusively to resolve mess-ups: Ungit is a great tool to understand the current state of the repository and fix it.
Re:Git undo: We can do better by an_opabinia on Monday June 21, 2021 @12:17PM (#27580654)
Not a single person I’ve met using git in the last decade has thrived using a UI for it.
Re:Git undo: We can do better by dragonwriter on Monday June 21, 2021 @12:24PM (#27580726)
> Not a single person I’ve met using git in the last decade has thrived using a UI for it.

I do most of my git through one or another UI (right now, mainly the integrated functionality in VSCode, a gitflow workflow extension for VSCode, and repository history graph extension for VSCode that supports doing operations against branches/tags/commits from the graph.) I feel loke I’m thriving that way.

Its not a substitute for knowing git, though, and I think that people who lean on a UI as a substitute for knowing what is going on underneath rather than as a convenience layer are not likely to thrive.

Re:Git undo: We can do better by oblio on Monday June 21, 2021 @12:23PM (#27580711)
That's a failing of Git. TortoiseSVN brought source control to millions of people. A good tool should be fully embeddable in a UI, 15 years after its launch.
Re:Git undo: We can do better by approxim8ion on Monday June 21, 2021 @01:27PM (#27581392)
We still use tortoiseSVN at work. It's crude but shockingly simple to use. Moving to git would be a significant expense just to train people not to break things and to get them used to CLI.
Re:Git undo: We can do better by somethingor on Monday June 21, 2021 @02:30PM (#27582191)
TortoiseGit exists too and is fantastic IMO: https://tortoisegit.org/
Re:Git undo: We can do better by approxim8ion on Tuesday June 22, 2021 @06:13AM (#27589846)
Wish they put some screenshots on their site, but I'm glad it does if it does to git what it does to SVN!
Re:Git undo: We can do better by pjmlp on Tuesday June 22, 2021 @02:18AM (#27588583)
Indeed, it makes using git so much less painfull.

There are days where I daydream of Clearcase when dealing with git.

Re:Git undo: We can do better by atulatul on Tuesday June 22, 2021 @03:54AM (#27589091)
Early in my career- when I got evil twin error- I was conditioned not to daydream of clearcase ever. :)
Re:Git undo: We can do better by pjmlp on Tuesday June 22, 2021 @07:05AM (#27590169)
On the positive side, messing up the view configurations doesn't wipe our files.
Re:Git undo: We can do better by OJFord on Monday June 21, 2021 @05:54PM (#27585024)
Or a success of git? No good GUI exists because they realise they'd just be recreating things that exist, but with a GUI frame?

If you wrote git 2.whatever from scratch would you structure rhe commands a bit differently? Yeah, sure, probably; but I always think these threads are way overblown. The common stuff that you use frequently.. well you use it frequently, so either you remember it as a result or you use the alias feature so that you can. For the less common stuff.. if you have to look it up in the excellent documentation, is that a failing?

Re:Git undo: We can do better by oblio on Tuesday June 22, 2021 @04:20AM (#27589247)
> if you have to look it up in the excellent documentation, is that a failing

Yes, if we ever want version control to become mainstream.

Version control is a very practical, day to day concept.

It's just almost unusable for regular folks.

And regular folks for sure won't use CLIs (unless you point a gun to their heads).

Re:Git undo: We can do better by OJFord on Tuesday June 22, 2021 @05:42AM (#27589662)
Version control is mainstream; git isn't, and isn't trying to be? Git is version control for plaintext files, (yes yes I know LFS exists) primarily software, and used by people who like using CLIs and have all kinds of other CLI tools for it to interface with.

Who's trying to make 'regular folks' use git, with or without a gun?

Re:Git undo: We can do better by dividedbyzero on Tuesday June 22, 2021 @07:20AM (#27590270)
> Who's trying to make 'regular folks' use git, with or without a gun?

I would have loved to have that option quite a few times. Lots of projects that involve software, but also get contributions from non-developers, or need almost no user-facing config, but not exactly zero. If git wasn't so hostile, quite a few tiny config web UIs I've built over the years could have been SublimeText or the like and a very userfriendly git client. It's kind of frustrating to have a repository with a directory full of .sql files, a CI pipeline that versions and verifies those and deploys the updated app, but the domain expert who is perfectly capable of writing the SQL still needs me to put the file in the right place and commit+push it, because they (understandably) just won't use git on Windows.

Re:Git undo: We can do better by OJFord on Tuesday June 22, 2021 @08:29AM (#27590810)
> they (understandably) just won't use git on Windows.

I'm not sure how understandable that is, especially in the age of WSL - but I just won't use Windows so what do I know :)

Re:Git undo: We can do better by lanstin on Monday June 21, 2021 @02:14PM (#27581957)
magit (for emacs) is quite good. But I still only use it for browsing around mostly, or single-file commits. For serious work, I start with git status, and then git diff all the changes, and then group them and then commit then in groups, then pull --rebase then push HEAD:good_branch_name (by the time I've done all the above, I have a better chance at a good name than I do for the first commit). Then over to PR land, where we have "ff if possible and delete source branch."
Re:Git undo: We can do better by animal_spirits on Monday June 21, 2021 @12:23PM (#27580709)
I've said this in other threads but I'll proselytize here as well. I really started to grok git after using the lazygit terminal UI. I think it's really handy to see what the current "state" of git is in and how to browse it easily. Would continue to recommend.

https://github.com/jesseduffield/lazygit

Re:Git undo: We can do better by swader999 on Monday June 21, 2021 @11:53AM (#27580379)
I agree and limit Git Gui usage to read-only use, any mods to git I use command line.
Re:Git undo: We can do better by yxhuvud on Monday June 21, 2021 @12:01PM (#27580460)
Git Gui is a decent tool to compose commits, but for everything else I can't see myself using anything but the command line.
Re:Git undo: We can do better by tcoff91 on Monday June 21, 2021 @12:07PM (#27580532)
I do virtually everything with Magit. It's the best of both worlds IMO. You still need to actually understand git and its commands but it's like using the CLI with far fewer keystrokes and a better log interface than the CLI.
Re:Git undo: We can do better by rjmunro on Monday June 21, 2021 @01:35PM (#27581488)
gitk (and similar) are great for browsing the history and figuring out what is going on. I couldn't live without it.