在Emacs的Magit中,与`git add --force`等效的添加被忽略文件的方法是什么?

6
我在我的.gitignore文件中添加了忽略当前git仓库中的.pdf文件的规则。但我想要将一个特定的pdf文件(example.pdf)添加到我的提交中。我使用Emacs和Magit
在Linux终端中,我通常会输入: git add example.pdf --force 然而,在Magit中我还没有找到相应的方法。
有什么建议吗?谢谢。
3个回答

1
Magit非常可定制。一个干净的方法是在magit状态缓冲区中添加一个“已忽略”部分。
通过将钩子添加到 magit-status-sections-hook 来插入和填充一个magit部分来实现此目的。这里的代码:https://emacs.stackexchange.com/a/28506/2731可能正是你想要的。

谢谢!这正是我正在寻找的东西。 - Nacho Cordón

0

偶尔我也需要将一个文件添加到我的 git 仓库中,但不希望被跟踪。我使用以下函数:

  (defun magit-add-current-buffer ()
    "Adds (with force) the file from the current buffer to the git repo"
    (interactive)
    (shell-command (concat "git add -f "
               (shell-quote-argument buffer-file-name))))

0
你可以尝试修改你的 .gitignore 文件,将 example.pdf(以及可能的其他文件)从被排除列表中删除:
# Ignore PDF
*.pdf

# But exclude certain files
!example.pdf

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接