taiyebur
taiyebur

Reputation: 429

How to notice incoming delete commit, if I don't want files to be deleted?

Suppose, I am pulling from origin where there are many new commits including commits that delete files. How to find out the files easily, so I can do 'git rm --cached ' and add them to .gitignore beforehand. I got some of my IDE specific config files deleted this way.

Is there any other solution to handle such scenario than to look through the commits?

Upvotes: 1

Views: 169

Answers (1)

torek
torek

Reputation: 488845

You can do this if you avoid git pull.

Remember that git pull means run git fetch, then run a second Git command. The git fetch step is safe: just run it yourself. The second command, usually git merge, is the one that may delete some of your work-tree files.

Once you have the commits—that's the git fetch step—you can inspect the commits to see if they will delete any of your existing tracked files. To do so, just compare your current index to the target commit you want to merge, with the --name-status option:

git diff --cached --name-status origin/master

for instance. You can add --diff-filter=D to check specifically for files that would be deleted by moving to origin/master.

If this says that your file(s) will be deleted, you can do your own git rm --cached, commit the result, and repeat the git diff to verify that they will no longer be deleted by the merge; then just run:

git merge origin/master

to do the second half of the git pull.

Upvotes: 2

Related Questions