Jibby
Jibby

Reputation: 1010

How to remove files from versioning in Git without deleting them, both locally AND ON A REMOTE repository

I have a versioned directory that contains a bunch of pdf resources that aren't really appropriate for versioning, but still need to be there alongside some html files that I actually do want versioned. The same folder exists on both a test server and a production server, and I use git to deploy changes from one server into the other. I want to remove the pdfs from versioning without deleting them from the working directory on either server.

I've used git rm -r --cached, which removes them from the git repo without deleting them from my working directory, and I've added them to .gitignore so Git won't see them as untracked files, but when I commit the changes and pull the changes into my other server all those pdfs get deleted from the working directory on the other server. I want them to stay. Any advice?

Note that this is not a duplicate of questions involving deleting from the cache without deleting from the local file system. It is about a distributed scenario.

Upvotes: 1

Views: 192

Answers (2)

AdmSteck
AdmSteck

Reputation: 1751

Do the following on the server:

  • git pull to get the changes, pdfs will disappear temporarily.
  • git reset HEAD~1 --hard This should move you back to the commit before the pdfs were removed. HEAD~1 is shorthand for the commit before the current commit. If the files were removed a few commits ago, you can replace HEAD~1 with the SHA of the commit before you removed the pdfs.
  • git reset ORIG_HEAD --mixed This will point your branch back at the correct commit and reset the staging area, but not reset the files in your working directory.
  • If the .gitignore was modified in the same commit as the pdfs were removed, you will need to git checkout -- .gitignore to get it back.

After these steps the pdfs should still be there and your repo should be up to date.

Upvotes: 1

Msp
Msp

Reputation: 2493

Follow these steps..

  1. Add all pdf files
  2. Push the code
  3. Update .gitignore
  4. Make a commit a push again

So that, the files on git server won't get deleted. But since they are in .gitignore, they won't be versioned. Means when you make a pull, you will have the pdfs too.

For example, look at this repo. It has two files, asd.txt and qwe.txt, where asd.txt is ignored using .gitignore. But still, when you pull the code, you will get both the files.

Upvotes: 0

Related Questions