0

Okay, I've created my first project with git, and everything's going well, but on my partner's computer, scripts and files that I've deleted are still present, resulting in some very strange behaviour.

How can I delete files from the repository? I don't want to to do this manually. I want files not present in my project to be completely purged from the repository. I want the repository to be an exact copy of my project files. I don't to merge, because I've deleted things that I want to be deleted.

Starkers
  • 10,273
  • 21
  • 95
  • 158

3 Answers3

1

When you do git rm some_file the file gets removed from the repository. You just need to commit it.

Once you have commited it, your partner can fetch from your repository (or a shared remote you both refer to) and merge your commits in. That would delete the files in his repository too.

Shahbaz
  • 46,337
  • 19
  • 116
  • 182
  • My only issue with this is that it'll still be in the git history, correct? If OP wants is to completely purge it from history, and that can only be done with a new repo AFAIK. – CDub Nov 06 '13 at 18:28
  • 1
    @CDub, it would be in the history. The OP didn't state that the files should also be purged from history. Still, if that is the case, [this github help page](https://help.github.com/articles/remove-sensitive-data) indicates how the history can be altered to remove that file. – Shahbaz Nov 06 '13 at 18:30
  • @Shahbaz So I need to go through the repo with a fine-toothed comb and rm all the files? – Starkers Nov 06 '13 at 18:41
  • @Starkers, actually no. If you have already deleted the files on your own repository, `git status` should show them as deleted (but not marked for staging). This means that if you do `git commit -a` which stages everything that has changed, it would automatically include deletion of all those files and make a commit out of it. – Shahbaz Nov 06 '13 at 18:45
  • Right! I see...give that a go – Starkers Nov 06 '13 at 19:19
1

Try the following on your Partner's Computer.

Mind you, as @Shahbaz has stated in the comments, this is a "Use with Caution" operation as any file(s) that is(are) on your Partner's local folder only will be gone.

git fetch --all
git reset --hard origin/master

git fetch downloads the latest from remote without trying to merge or rebase anything.

git reset resets the master branch to what you just fetched.

Source: This SO Comment:

Community
  • 1
  • 1
Shiva
  • 20,575
  • 14
  • 82
  • 112
  • Worth saying this should be done on the partner's computer. If on the same computer where the files are deleted, it would restore the files again. Also, if there are unpushed commits they would be lost. In general, this is a kind of dangerous operation. – Shahbaz Nov 06 '13 at 18:47
0

I don't believe you can do this in git. If you want the files completely purged from the git history, you'll need to delete the origin repo and recreate it based on your project files.

If you're okay with them being in the history of the project, then git rm <some-file will suffice.

CDub
  • 13,146
  • 4
  • 51
  • 68