git - 由于编辑器没有自动更新,有没有办法防止 git pull 后意外覆盖?

标签 git editor sublimetext2 sublimetext3 atom-editor

当一个文件在编辑器(例如 Sublime 或 Atom)中打开,并且该文件是在编辑器外编辑的时,编辑器总是拒绝刷新它显示的文件。这种情况很少发生,因为人们很可能只会在特定时间范围内使用单一工具来编辑文件。当文件为只读时,这显然不是问题。例如读取系统错误日志时,文件会随着系统的运行而更新,可能会有新的错误日志,但日志文件不会被编辑,所以不会造成冲突。

但是,当通过 git pull 更新文件时,它会导致问题。

当某人将最新的更新 pull 到存储库时,他可能会在编辑器中打开一个文件,该文件已在更新中进行了一些更改。如果编辑器刷新文件失败,文件将保存为旧内容,任何新的更改都将丢失。

有时,使用 sourcetree 来反转 hunk 很烦人,但是当有许多文件更新时,覆盖可能会被推送到 git 服务器而不被注意——直到发生错误。目前我们正在使用git log --follow -p -- file命令来定位和恢复错误,但如果没有及时发现覆盖是不可能的,迫使我们手动复制行.有没有办法从一开始就防止这种覆盖?

最佳答案

When a folder is opened by an editor (mainly Sublime or Atom in our team), and the code is edited outside the editor, sometimes the content in the editor is refreshed, but sometimes it doesn't.

这正是 Atom issue 3594 中讨论的内容

file-watcher 这样的 Atom 包如果检测到编辑器外的修改,提示重新加载每个文件,将有助于缓解此问题。

你有同样的问题reported in this thread对于 SublimeText。 如 that thread 中所述,当通过网络共享访问文件时,该问题在 Windows 上更为相关。
File Reloader可以提供帮助,但无法检测到外部变化。

SublimeText thread提到设置(2016)

{ "always_prompt_for_file_reload": true }

但是当编辑器和保存的文件都发生变化时,这可能无济于事:一个 editor like Visual Studio Code解决这个问题:

If there are changes on both sides (from disk and through the editor) when ever you try to save the file using VSCode, the editor will warn you about that situation and a file comparison will allow you to decide what to do.

这就是为什么使用 SublimeText(除了 "always_prompt_for_file_reload" 设置),您可能需要 FileDiff plugin .
它确实允许使用 Saved 比较文件:

https://forum.sublimetext.com/uploads/default/original/3X/5/a/5a59f922e26fea423cc31ae5c1d744eca8205143.png

关于git - 由于编辑器没有自动更新,有没有办法防止 git pull 后意外覆盖?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40297669/

相关文章:

git - 无法在 Git 中推送或 pull

git - 如何为 HTTPS git push 设置默认用户名?

regex - 在 vim 中查找并替换整个单词

java - 自定义 Eclipse 透视图中的多个编辑器区域

python - 有没有办法将 KeyboardInterrupt 发送到 Sublime Text 中正在运行的 Python 脚本?

git pull 必须被调用两次——获取后停止,然后只执行 merge

git - github 52 周参与如何运作?

intellij-idea - Intellij 喜欢文本编辑器

sublimetext2 - 如何诊断和修复 Sublime Text 3 中的键绑定(bind)冲突

vim - Vim 中的多选