What is the Magit equivalent of git add [--intent-to-add] <filename>
for checking a newly created file into Git?
-
At some point, perhaps someone will put together a cheat-sheet that converts command line options (in alphabetical order) to magical Magit keboard shortcuts. It should not be necessary (in my opinion) to read the manual -- that is why G*d created an index -- i.e., read just whatever is relevant to the task at hand.– lawlistSep 3, 2015 at 2:01
-
1It doesn't map command line to magit, but there is a refcard: magit.vc/manual/magit-refcard.pdf.– tarsiusSep 3, 2015 at 15:00
-
@tarsius: It would be sensible to add a "git add" index entry pointing to the "Staging and Unstaging" node of the manual.– philsJun 21, 2017 at 23:54
3 Answers
To stage a change press s with point on any "stageable change". This includes files listed below "Untracked files" and "Unstaged changes".
You can also expand the files below "Unstaged files" using TAB (also works for many other sections) to see the hunks. You can then stage an individual hunk, again by pressing s while point is inside it.
You can even stage just parts of a hunk using the region. To do that press C-SPC to mark the beginning of the region and then n a few times to move to where the region should end.
In order to git add --intent-to-add
, use C-u s.
You can also unstage, discard, reverse, and apply changes in a similar fashion. This is described in more detail in the manual. In particular see Staging and unstaging, Applying, and Sections. Staging is also covered in Getting Started.
-
6
s
will stage a file. But how can i just add file, so that git will start tracking file but not stage all changes? Nov 12, 2015 at 11:48 -
9
-
2When the git config "showUntrackedFiles = no" is set, staging with "s" is not possible as the files are not displayed. In that case @glucas answer is the way to go. i.e "magit-stage-file". For those who are wondering why would someone disabled tracking files, the workflow is common when the main repo is managed by some other vc like perforce and git is used as a local vc within the vc then in such scenario disabling tracking speeds up significantly Jan 17, 2020 at 9:29
-
-
Start with magit-status
, then move to the file name under the "Untracked files" heading and hit s
to stage it.
If what you're looking for is a way to add/stage a file directly from its buffer: try the command magit-stage-file
. If you do that a lot you could bind it to a key.
As others have already pointed out, the more common way to stage/add files is from the magit-status
buffer.
-
magit-stage-file asks for file to stage. Doesn't directly stage it Sep 5, 2017 at 15:52
-
That's not how it behaves for me. Also from the doc: "With a prefix argument or when there is no file at point ask for the file to be staged. Otherwise stage the file at point without requiring confirmation."– glucasSep 5, 2017 at 15:54
-
Ah, I see: For a new file it does in fact prompt. If the file already exists (and you are staging changes) it does so silently. Thanks for pointing that out.– glucasSep 5, 2017 at 15:59