9

i'm having a hard time understanding hg forget. is it the same as git rm --cached? i.e. will remove the file with the next commit and stop tracking it?

knittl
  • 246,190
  • 53
  • 318
  • 364
  • 2
    Maybe the accepted answer here helps you: http://stackoverflow.com/questions/1101167/what-is-the-difference-between-hg-forget-and-hg-remove – ZeissS Nov 09 '10 at 15:39

1 Answers1

9

hg forget tells mercurial to stop tracking a file, but doesn't alter the file in your working directory.

After your commit it will behave as if you never did a hg add (though of course history will still exist). New clones won't have that file in their working dir, but it won't be deleted in your working dir.

If you want to have a file in the workingdir/manifest, but want to ignore future changes, there's no easy way to do it (because it's generally considered a bad idea), though you can fake it by aliasing things to use -I on hg commit.

The better way to do that is to commit a sample of the file you want in the repo but whose changes you want ignored and then have your build system (or your instructions) copy that to its non-sample location. For example have a file config-file.sample that is tracked in the repo, and then have setup/installation/build do a cp config-file.sample config-file if config-file doesnt' exist. Include config-file in your .hgignore so it doesn't accidentally get added. That gives you a tracked baseline but doesn't risk committing and pushing your local customizations. This is very commonly done for things like database paths.

Ry4an Brase
  • 78,112
  • 7
  • 148
  • 169
  • I think git rm --cached is like hg rm --after – tonfa Nov 09 '10 at 16:02
  • but it will be deleted from the next commit and onward? the way you describe it, is exactly where my confusion comes from. stops tracking: does that mean future changes will be ignored or will the file be deleted from the manifest – knittl Nov 09 '10 at 16:02
  • 1
    Deleted from the manifest. as evidenced by my statement "New clones won't have that file in their working dir". – Ry4an Brase Nov 09 '10 at 16:47
  • 4
    for the record: `hg forget` is the same as `git rm --cached` (my original question) – knittl Feb 20 '11 at 12:05
  • `git rm --cached` is NOT the same as `hg forget` as the latter does NOT remove the local files (if they were previously added & committed).. it's the same as `hg remove`... learned the hard way.. – OZZIE Nov 06 '17 at 07:09