dailyhack icon indicating copy to clipboard operation
dailyhack copied to clipboard

Ignoring a previously committed file quickly

Open sashadev-sky opened this issue 6 years ago • 2 comments

Files already tracked by Git are not effected by the .gitignore file.

If you want to ignore a file that you've committed in the past,

  • Use echo with >>(double redirection arrow) to append a relative file path to your .gitignore directly from the terminal.
  • Use git rm with the --cached option to delete the file from your remote repository, but keep it in your working directory as an ignored file.
  • Commit.
$ echo debug.log >> .gitignore
$ git rm --cached debug.log
rm 'debug.log'
$ git commit -m "Start ignoring debug.log"

sashadev-sky avatar Apr 11 '19 10:04 sashadev-sky

Thanks, @sashadev-sky this is what we called cool hack.

mddanishyusuf avatar Apr 11 '19 10:04 mddanishyusuf

Nice, thanks for sharing this!

fajarsiddiqfs avatar Apr 11 '19 20:04 fajarsiddiqfs