I'm using Gedit, and each time I save a file, Gedit creates a copy of it, and the name of the copy always ends with a ~. The problem is, Git always tries to track these files, and I don't want that! Is there a way to still be able to use git add .
, but add just those files that do not end with ~?
It is happening because you may have the . git file in root directory. Show activity on this post. Run git reset HEAD to unstage all staged changes without undoing the changes in your working tree.
What you probably want to do is this: git update-index --skip-worktree . (The third option, which you probably don't want is: git rm --cached .
If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.
gitignore is the way to go. Just add *~
to .gitignore
at the root of you repo.
You want a gitignore file.
If you want to nuke everything that ends with a tilde (which should be safe; I can't imagine a reasonable use-case where that's bad), make sure the following line is in your .gitignore
file at the top of your repo's folder hierarchy:
*~
If you also want to get rid of those tilde files laying around in your local file system, you can. It'd be best to make Gedit put its backup files somewhere else. JEdit and VIm, the two editors I use most, have such settings, and it's lots cleaner to keep those somewhere else than loading up gitignore.
Unfortunately, Gedit doesn't have that option. The best it can do is to turn off the ~
backups. Before you get worried, the worst case is that you lose what was in the file immediately before you saved. That's not a worst-case -- that's why you've got this in a git repo, right?
NOTE: If you want to keep the ~
suffixed files locally, do. The .gitignore you set up, above, will keep you from accidentally sharing them.
You can turn off ~
suffixed backups like this
To prevent Gedit from creating these backups in the future, open up Gedit, open up the Preferences dialog (Edit > Preferences), select the Editor tab, remove the check in the “Create a backup copy of files before saving” option, and click Close. After doing this, Gedit will no longer make the backups with tildes all over the place.
To add on to what @filmor said, you can create a global gitignore file so that all repositories will ignore the backup files:
git config --global core.excludesfile ~/.gitignore_global
This will tell git to look in your $HOME path for a .gitignore_global
file, which is where you can place the *~
rule.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With