Daniel
Daniel

Reputation: 2726

Git: why the file deletion does not sync?

Newbie here. I have two linux workstations, WS-A and WS-B.

I have a project on WS-A and and then pushed it to my remote repo on bitbucket.

And then I git clone on WS-B and then I made a few modifications and deleted some files on WS-B due to some reasons and then on WS-B I pushed again.

But I am very confused, on WS-A now, when I do a git pull, the deleted files are still there!! What should I do? I am 100% sure I want them to be deleted. I am the only user of this code. I want to keep ONLY ONE version.

Upvotes: 4

Views: 9353

Answers (2)

thedoctori
thedoctori

Reputation: 25

A tangible example should help developers struggling with cleaning files out of a repo that have been deleted and that have been marked by Git as "deleted." If you don't permanently remove those "deleted" files, Git will show them to you every time you do a git status. It's hard to read the output from git status when there are many "deleted" files hanging around.

1) Check your repo's status with git status:

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
    (use "git add/rm <file>..." to update what will be committed)
    (use "git checkout -- <file>..." to discard changes in working directory)
        deleted:    repoDir/subDir/Info.plist
        deleted:    repoDir/subDir/MacOS/CrashLogDemo
        deleted:    repoDir/subDir/PkgInfo...

no changes added to commit (use "git add" and/or "git commit -a")

2) Use git rm to permanently remove files Git has marked "deleted" (in this case I'm using a wildcard [*] to remove an entire directory):

$ git rm repoDir/subDir/*
rm 'repoDir/subDir/Info.plist'
rm 'repoDir/subDir/MacOS/CrashLogDemo'
rm 'repoDir/subDir/PkgInfo'...

3) Commit changes with a comment using git commit -m:

$ git commit -m "Removed unncessary files."
[master 9178ad4] Removed unncessary files.
    28 files changed, 2377 deletions(-)
    delete mode 100644 repoDir/subDir/Info.plist
    delete mode 100644 repoDir/subDir/MacOS/CrashLogDemo
    delete mode 100644 repoDir/subDir/PkgInfo...

4) git push the changes to the appropriate repo/branch:

$ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 291 bytes | 291.00 KiB/s, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/accountName/CrashLogDemo.git
    f4716fa..9178ad4  master -> master

5) Finally, when other users do a git pull, the unnecessary files will be deleted from their locals.

Upvotes: 2

quickshiftin
quickshiftin

Reputation: 69731

Yes you have to use git rm, otherwise the files have been deleted on the working copy, but not from the repository. git status should show the files as 'deleted', but not staged for commit. git rm; git commit and git push them, then git pull from the other box and they will be gone.

Upvotes: 3

Related Questions