Equivalent of `git add --force` to add ignored files in Emacs' Magit
Asked Answered
B

3

7

I have a rule in my .gitignore to ignore .pdf files in my current git repo. But I'd like to add a pdf in particular to my commit (example.pdf). I'm working with Emacs and Magit.

In a Linux terminal I would usually type:

git add example.pdf --force

Although, I haven't found an equivalent way of doing so in Magit.

Any ideas? Thanks

Board answered 17/10, 2016 at 16:10 Comment(0)
E
1

Magit is very customizable. One clean method of adding this functionality would be to add an "Ignored" section to the magit status buffer.

Do this by adding a hook to magit-status-sections-hook to insert and populate a magit section. The code here: https://emacs.stackexchange.com/a/28506/2731 is probably exactly what you want.

Esma answered 8/12, 2016 at 17:12 Comment(1)
Thanks! That's exactly the kind of thing I was looking for.Fudge
C
0

You can try modifying your .gitignore file to exclude example.pdf (and possibly other files) from being excluded:

# Ignore PDF
*.pdf

# But exclude certain files
!example.pdf
Calculator answered 17/10, 2016 at 16:19 Comment(0)
P
0

From time to time, I also have to add a single ignored file to my git repo. I use the following function:

  (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))))
Prostatitis answered 21/9, 2019 at 18:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.