How to undo all added files in Mercurial
Asked Answered
C

4

30

Say I type hg add in Mercurial, and there a bunch of untracked files in my working directory that are not ignored. What is the easiest way to un-add all those files without explicitly typing the name of each file?

Can I just un-add them all with one command?

Cinchonism answered 27/3, 2013 at 20:13 Comment(1)
Duplicate of #6183874Galyak
S
30

Preface

You must always ask questions, which contain as much information as possible. Because now your question, depending from some conditions, may have totally different answers.

Case One - no local modifications in already versioned files, only added (and not committed) files

hg revert will return your working directory to the state after the last commit, undoing all changes it it.

Case One - local edits, which you want to save and occasionally added files

  1. Read about filesets in Mercurial.
  2. Use fileset in the hg forget command, something like hg forget "set:added()".
Soiree answered 27/3, 2013 at 20:54 Comment(0)
L
29

Use hg revert or hg forget on the files (both do the same for a file you ran hg add on). To avoid typing out the filenames, you can use a fileset like this:

$ hg revert "set:added()"

This will revert the file back to how it looked in the working copy parent revision, i.e., it will become unknown again.

Leyva answered 28/3, 2013 at 8:39 Comment(2)
Hi, Martin. Presumably this is more refined than just hg revert -a, which would also revert changes to existing files, correct?Dextrose
@FaheemMitha Yes, exactly.Leyva
H
0

hg revert -r .^ path-to-file will revert the commit from the commit-set. then commit and submit (if using jelly fish) and you'll see the files removed from the changeset. I don't know why .^ works yet, but somebody will probably know.

Hokum answered 26/4, 2019 at 20:41 Comment(1)
Hi there. Your post more like a comment. Please add more details or delete it.Carpentaria
L
-2

You could always just re-clone your repository and then replace (delete existing and then copy new) the .hg directory in your working folder with the one from the fresh clone... (assuming you have no pending commits..)

Langlauf answered 27/3, 2013 at 20:21 Comment(1)
This seems workable in theory but maybe error prone. I guess if you had a huge amount of local changes you didn't want to manually reproduce in a new clone this might be the best choice. Creative solution anyway!Imitate

© 2022 - 2024 — McMap. All rights reserved.