防止magit`:`切换到另一个窗口

发布于 2024-11-01 18:07:15 字数 319 浏览 1 评论 0原文

在 shell 中使用 git 几个小时后,我切换到 magit。

它非常简洁和高效:我不再需要输入“git”来调用 git 命令!

但与 shell 命令行相比,我仍然发现了一个缺点。

每次我输入 : 来调用 git 命令时,输出都会在另一个窗口中弹出。我必须输入 Cx o 才能切换回来,然后再次输入 git 命令。

除了 Emacs 中的 shell-mode 之外,还有更好的方法可以同时保持输入和观察输出吗?

我应该将输出重新绑定到其他模式吗?哪一个?或者更优雅的解决方案?

After several hours of using git in the shell, I switched to magit.

It's pretty neat and efficient: I don't need to type "git" to invoke a git command anymore!

But I still found one drawback comparing to the shell command line.

Every time I typed : to invoke a git command, the output popped out in the other window. I had to type C-x o to switch back then type the git command again.

Is there a better way to keep typing and watching on the output at the same time other than shell-mode in Emacs?

Should I rebind the output to some other mode? Which one? or a more elegant solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

粉红×色少女 2024-11-08 18:07:15

我同意布莱恩的观点,你想做什么是魔法师通过简单的按键触发器无法做到的?可能已经有一个键绑定了。如果不是,我只需 Cz 进入 shell 并运行命令,然后输入 fg 将 emacs 返回到前台。

编辑:我的流程是这样的。

  1. 我开始新的一天的工作。我在命令行中输入 git diff 只是为了看看前一天是否有任何未提交的更改(不要忘记 启用颜色!)我在命令行中这样做而不是在 magit 中这样做的原因是因为我还没有使用 emacs。
  2. 我要么在 emacs emacs file1 file2 中打开未提交的文件,要么打开一些我要处理的文件。
  3. 我一直编码,直到修复了错误或完成了新功能。
  4. 在 emacs 中,我输入 Cc i 打开 Magit 状态窗口。
  5. 我向下滚动到“更改”部分,然后按每个文件旁边的 Tab 键查看每个更改的差异。我可以按 s 暂存这些更改,也可以按 u 取消暂存这些更改。
  6. 或者,我可以查看差异代码并执行相同的 su 来暂存和取消暂存代码部分。如果我在某处有一些调试代码并且想要杀死它,这很有用。
  7. 在确认所有更改看起来不错并已上演后,我输入 c 打开 magit-edit-log。我输入提交消息,然后输入Cc Cc 进行提交。然后P来推送它。完毕!

请注意,这听起来像是很多步骤,但它很快就会变得自然,整个过程实际上需要 30 秒,我才能比较我的整个更改集,暂存它们,并通过消息提交它们。一直在 Emacs 中进行。比直接进入命令行要容易得多。

有时,当我通过 Magit 进行推送时会返回错误,通常是由于远程存储库中的新代码导致我必须在推送之前拉取。在这种情况下,F 会拉取更改,然后再次 P 会推送。老实说,出于某种原因,在这种情况下,我通常只是 Ctrl-z,下拉到 shell、git pullgit Push<,而不是通过 Magit 拉取。 /代码>。

编辑:我想我记得 Magit 的默认差异颜色非常糟糕。我在我的 .emacs 中使用了以下内容,我确信我是从某个地方偷来的:

;; change magit diff colors                                                                                                                                                                                 
(eval-after-load 'magit                                                                                                                                                                                     
  '(progn                                                                                                                                                                                                   
     (set-face-foreground 'magit-diff-add "green3")                                                                                                                                                         
     (set-face-foreground 'magit-diff-del "red3")                                                                                                                                                           
     (when (not window-system)                                                                                                                                                                              
       (set-face-background 'magit-item-highlight "black"))))                                                                                                                                               

(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG$" . diff-mode))                                                                                                                                             
(eval-after-load 'diff-mode                                                                                                                                                                                 
  '(progn                                                                                                                                                                                                   
     (set-face-foreground 'diff-added "green4")                                                                                                                                                             
     (set-face-foreground 'diff-removed "red3")))

I agree with Brian, what are you trying to do that magit can't do via a simple key trigger? There's probably a key-binding for it already. If not I just C-z to drop to shell and run the command, then type fg to bring emacs back in foreground.

Edit: My flow goes like this.

  1. I start the day at work. I type git diff in command line just to see if I have any uncommitted changes from the previous day (don't forget to enabled colors!) The reason I do this in command line as apposed to magit is because I'm not in emacs yet.
  2. I either open the uncomitted files in emacs emacs file1 file2 or I open some files I'm about to work on.
  3. I code until I've fixed a bug or finished a new feature.
  4. In emacs I type C-c i to open up the Magit status window.
  5. I scroll down to the Changes section and next to each file press tab to see a diff of each changes. I either press s to stage those changes or u to unstage those changes.
  6. Optionally, I can look through diffs code and do the same s and u to stage and unstage sections of the code. Useful if I had some debug code somewhere and want to kill it.
  7. After I've confirmed all my changes look good and are staged I type c to open the magit-edit-log. I type my commit message and then type C-c C-c to commit it. Then P to push it. Done!

Note that this sounds like a lot of steps but it becomes quickly natural and the whole process literally takes 30 seconds for me to diff my entire set of changes, stage them, and commit them with a message. All while staying in Emacs. So much easier than dropping down to command line.

Sometimes an error is returned when I do a push via Magit usually caused by new code in the remote repo that I have to pull before I push. In this case F to pull changes then P again to push. Honestly for some reason, instead of pulling through magit, I generally just Ctrl-z in this situation, drop down to shell, git pull, and git push.

Edit: I think I remember Magit's default diff colors being pretty atrocious. I use the following in my .emacs I'm sure I stole from somewhere:

;; change magit diff colors                                                                                                                                                                                 
(eval-after-load 'magit                                                                                                                                                                                     
  '(progn                                                                                                                                                                                                   
     (set-face-foreground 'magit-diff-add "green3")                                                                                                                                                         
     (set-face-foreground 'magit-diff-del "red3")                                                                                                                                                           
     (when (not window-system)                                                                                                                                                                              
       (set-face-background 'magit-item-highlight "black"))))                                                                                                                                               

(add-to-list 'auto-mode-alist '("COMMIT_EDITMSG$" . diff-mode))                                                                                                                                             
(eval-after-load 'diff-mode                                                                                                                                                                                 
  '(progn                                                                                                                                                                                                   
     (set-face-foreground 'diff-added "green4")                                                                                                                                                             
     (set-face-foreground 'diff-removed "red3")))
向地狱狂奔 2024-11-08 18:07:15

当我使用 Magit 时,我通常使用 Magit 的内置命令来完成大部分工作,而当我需要执行 Magit 内置命令无法完成的操作时,只需使用常规终端即可。 Magit 有内置命令几乎可以满足我的日常使用;你经常使用哪些 Magit 不提供的功能,而且你无论如何也不会在成熟的终端中使用?

I usually use Magit's built in commands for most of my work when I'm using Magit, and just use a regular terminal when I need to do things that I can't do from Magit's built in commands. Magit has built in commands for almost all of my day to day usage; what are you using regularly that Magit doesn't supply and you wouldn't be doing in a full-fledged terminal anyhow?

心头的小情儿 2024-11-08 18:07:15

关于 magit-run* 的建议解决了这个问题。可能会中断对 magit-run* 的其他调用,我没有进一步测试......

(defadvice magit-run* (around stay-in-magit activate)
  (flet ((pop-to-buffer (buf &optional act rec) (display-buffer buf act)))
    ad-do-it))

An advice on magit-run* solves this. Might disrupts other calls to magit-run*, I didn't test this further...

(defadvice magit-run* (around stay-in-magit activate)
  (flet ((pop-to-buffer (buf &optional act rec) (display-buffer buf act)))
    ad-do-it))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文