News for hackers. Stuff that matters.
Re:Magit, the magical Git interface (2017) by wodenokoto on Friday October 22, 2021 @05:59AM (#28955368)
Can I like magit if I don’t like emacs?
Re:Magit, the magical Git interface (2017) by sokoloff on Friday October 22, 2021 @06:24AM (#28955489)
You can, but it will be worth it for you to spend a little effort to learn the basic buffer, window, and cursor management keystrokes.

My 12 year old uses magit as a git interface and nothing else in emacs. That’s not a great testimonial as it was my direction to do that, but it seems to work just fine.

The areas where magit earns outsized praise is not around a basic “pull, add and commit everything, push” workflow, but rather around being selective about crafting self-consistent but single-theme revisions. That will not be as fluid for someone with no fluency in emacs keyboard navigation, but I think I’d still find it easier than using the git command line to do it. (Hard for me to say with 30 years of emacs in the rear view.)

Re:Magit, the magical Git interface (2017) by jolmg on Friday October 22, 2021 @06:52AM (#28955653)
> but rather around being selective about crafting self-consistent but single-theme revisions

Actually, I think git's got Magit beat on that. Magit might make it easier to stage specific lines, but git can stage specific parts of lines or even changes that are completely different than what's on the worktree, through the editing of diffs with `git add -p`'s `e` option.

Re:Magit, the magical Git interface (2017) by TeMPOraL on Friday October 22, 2021 @07:48AM (#28956100)
I'm somewhat convinced you can replicate that last feature (staging arbitrary / sub-line pieces of your changes) through ediff-staging (E s), but ediff is a complex tool in itself, and I don't know how to use it properly yet.

(Ediff is a 2-way / 3-way interactive diffing interface, built into Emacs, with plenty of features for surgical diffing of files, buffers, directories and whatnot.)

Re:Magit, the magical Git interface (2017) by NateEag on Friday October 22, 2021 @10:35AM (#28957738)
Magit has great support for staging parts of lines - select the section you want to stage and press 's'.
Re:Magit, the magical Git interface (2017) by amake on Friday October 22, 2021 @10:41AM (#28957831)
> Magit has great support for staging parts of lines

This is news to me.

> select the section you want to stage and press 's'.

It stages line-wise for me. How do I get it to stage less than an entire line?

Re:Magit, the magical Git interface (2017) by fouric on Friday October 22, 2021 @11:42AM (#28958601)
When your press 's', you should have a region selected, in order to stage that region - if your cursor is just sitting on a line without selecting part of it, you'll (probably) just get the whole line staged.
Re:Magit, the magical Git interface (2017) by amake on Friday October 22, 2021 @06:48PM (#28963689)
When I press s, the entire line is staged even if my region is a subset of that line.
Re:Magit, the magical Git interface (2017) by NateEag on Friday October 22, 2021 @09:36PM (#28964842)
...huh. I just tested this in my Emacs instance and it works as you describe.

I could swear I remember this working in the past, but I can find no hint of it in a few quick searches, so I'm likely mistaken.

I'm sorry for the misinformation.Thanks for saying something.

Re:Magit, the magical Git interface (2017) by PaulDavisThe1st on Friday October 22, 2021 @11:22AM (#28958365)
The second line you quoted tells you how.
Re:Magit, the magical Git interface (2017) by amake on Friday October 22, 2021 @06:50PM (#28963708)
It does not. As I said, pressing s does not stage less than a line for me, even if my region is a subset of the line.
Re:Magit, the magical Git interface (2017) by gpderetta on Friday October 22, 2021 @11:47AM (#28958654)
When selecting only part of line, 's' will still stage the full line for me.
Re:Magit, the magical Git interface (2017) by jolmg on Friday October 22, 2021 @12:03PM (#28958871)
Indeed.

  cd $(mktemp -d)
  git init
  echo bar > file.txt
  git add file.txt
  git commit -m "init"
  echo foo_bar_baz > file.txt
  # select only "foo_" in magit-status and press "s"
  git diff --cached
will show

  diff --git a/file.txt b/file.txt
  index 5716ca5..2fd000c 100644
  --- a/file.txt
  +++ b/file.txt
  @@ -1 +1,2 @@
   bar
  +foo_bar_baz
rather than the desired

  diff --git a/file.txt b/file.txt
  index 5716ca5..2fd000c 100644
  --- a/file.txt
  +++ b/file.txt
  @@ -1 +1,2 @@
  -bar
  +foo_bar
I can't really imagine this feature working that well with just selection. Editing of the diff seems required.

I just updated magit, too. It seems to have been published 3 days ago.

Re:Magit, the magical Git interface (2017) by NateEag on Friday October 22, 2021 @09:37PM (#28964848)
..huh. I just tested this in my Emacs instance and it works as you describe.

I could swear I remember this working in the past, but I can find no hint of it in a few quick searches, so I'm likely mistaken.

I'm sorry for the misinformation. Thanks for saying something.

Re:Magit, the magical Git interface (2017) by dan-robertson on Friday October 22, 2021 @07:24AM (#28955887)
What percentage of git users do this compared to the percentage of magit users staging line-by-line or confidently amending/cherry-picking/interactive-rebasing?
Re:Magit, the magical Git interface (2017) by stinos on Friday October 22, 2021 @07:31AM (#28955937)
In my experience: yes but it I have the impression it'll remain a bit of a struggle unless you go all in and learn emacs as well.

After hearing so much good of Magit in a previous thread here I thought 'ok why not?' and installed emacs and magit. That alone wasn't a walk in the park as I never used emacs before. Maybe I did something wrong but what I remember from it is mainly 'wtf x 10 and what kind of documentation is this'. After some hours I got the hang of it, and I see why it is liked, but still it didn't make me any faster with git because I already have everything needed for my main workflows (SublimeMerge + aliases). Also felt like to get any real value from it I'd need many extra hours on the learning curve and it wasn't clear to me whether the end result would actually be better than what I do now. So I skipped on it, but again: I fully understand that if you use emacs anyway it would be crazy not to use magit.

Re:Magit, the magical Git interface (2017) by pbiggar on Friday October 22, 2021 @10:36AM (#28957754)
There's a VSCode plugin based on magit. In my experience, it's basically identical (though occasionally a bit slow when there's lots of files).

https://marketplace.visualstudio.com/items?itemName=kahole.m...

Re:Magit, the magical Git interface (2017) by mgr8 on Friday October 22, 2021 @06:52AM (#28955649)
you can try https://github.com/jesseduffield/lazygit, i think its quite similar. It is a TUI for git. It has made my git workflow very friction-less. Makes it very easy to cherry-pick commits, rebases, selecting chunks of files to add in atomic commits, and simplifies the resolutions of merge conflicts. It is also integrated into lunar vim if vim is more up your alley
Re:Magit, the magical Git interface (2017) by caskstrength on Friday October 22, 2021 @07:35AM (#28955988)
Depends on what you mean by not liking emacs. If you prefer vim, then you can just install Evil to get similar-ish modal keyboard controls. If you are more of an IDE-person who likes controlling stuff with a mouse in VS or IntelliJ, then probably no.
Re:Magit, the magical Git interface (2017) by agumonkey on Friday October 22, 2021 @10:02AM (#28957287)
I believe magit underlying ideas are good no matter what software you use, it's not an emacs only principle.

It's just keyboard oriented, text-light interaction design if you will.

invoke versionning (key 1), see what's changed, pick the parts you like (few navigations keys and 2 keys to pick/unpick), invoke commit (key 4) write and accept (key 5) (amend is key 6 if you made a mistake)

It's just fast, lean and tailored. Apparently people did it in vi too. I just wish it was the case in more places. Actually, whenever I write a vuejs thing, I try to embed keyboard as much as possible.

Re:Magit, the magical Git interface (2017) by b0afc375b5 on Friday October 22, 2021 @06:50AM (#28955633)
Absolutely. I can honestly say I learned Magit first (since it was directly applicable to my job) before I "properly" learned emacs.
Re:Magit, the magical Git interface (2017) by coyotespike on Friday October 22, 2021 @10:38AM (#28957772)
I used my own emacs for several years, then switched to Spacemacs. It's far easier to learn and use for most people, and also works with Vim keybindings. I'd recommend giving it a try.
Re:Magit, the magical Git interface (2017) by weaksauce on Friday October 22, 2021 @12:23PM (#28959156)
if you like vim i'd suggest you install spacemacs and the git layer.