What is the Magit equivalent ofgit 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.lawlist– lawlist2015-09-03 02:01:52 +00:00CommentedSep 3, 2015 at 2:01
- 1It doesn't map command line to magit, but there is a refcard:magit.vc/manual/magit-refcard.pdf.tarsius– tarsius2015-09-03 15:00:37 +00:00CommentedSep 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.phils– phils2017-06-21 23:54:48 +00:00CommentedJun 21, 2017 at 23:54
3 Answers3
To stage a change presss 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" usingTAB (also works for many other sections) to see the hunks. You can then stage an individual hunk, again by pressings while point is inside it.
You can even stage just parts of a hunk using the region. To do that pressC-SPC to mark the beginning of the region and thenn a few times to move to where the region should end.
In order togit add --intent-to-add, useC-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 seeStaging and unstaging,Applying, andSections. Staging is also covered inGetting Started.
- 6
swill stage a file. But how can i just add file, so that git will start tracking file but not stage all changes?Chillar Anand– Chillar Anand2015-11-12 11:48:34 +00:00CommentedNov 12, 2015 at 11:48 - 9@ChillarAnand You can now do that using
C-u s.tarsius– tarsius2016-05-24 22:24:22 +00:00CommentedMay 24, 2016 at 22:24 - 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 significantlyTalespin_Kit– Talespin_Kit2020-01-17 09:29:51 +00:00CommentedJan 17, 2020 at 9:29
- How to add all untracked files at once?Emmanuel Goldstein– Emmanuel Goldstein2021-02-02 04:06:37 +00:00CommentedFeb 2, 2021 at 4:06
- Press
swhile point is on the section title "Untracked files".tarsius– tarsius2021-02-02 09:02:02 +00:00CommentedFeb 2, 2021 at 9:02
Start withmagit-status, then move to the file name under the "Untracked files" heading and hits to stage it.
If what you're looking for is a way to add/stage a file directly from its buffer: try the commandmagit-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 themagit-status buffer.
- magit-stage-file asks for file to stage. Doesn't directly stage itsprajagopal– sprajagopal2017-09-05 15:52:10 +00:00CommentedSep 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."glucas– glucas2017-09-05 15:54:25 +00:00CommentedSep 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.glucas– glucas2017-09-05 15:59:13 +00:00CommentedSep 5, 2017 at 15:59
Explore related questions
See similar questions with these tags.