Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git prevent deleting ingored files

Tags:

git

gitignore

I need to have two different version of same file - one on local machine and one on the server (repo).

I have put file to .gitignore, but now during each push it will delete file on the repo.

What to do to prevent deleting file on the repo? Thank you!

like image 244
CodeBy Avatar asked Oct 30 '22 11:10

CodeBy


1 Answers

Use this flag to mark your local changes as unchanged so git will not track any changes including your file delete.

To temporarily ignore changes in a certain file, run:

git update-index --assume-unchanged <file>

When you want to track changes again:

git update-index --no-assume-unchanged <file>

--[no-]assume-unchanged

When this flag is specified, the object names recorded for the paths are not updated.
Instead, this option sets/unsets the "assume unchanged" bit for the paths.

When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

enter image description here

like image 184
CodeWizard Avatar answered Nov 15 '22 05:11

CodeWizard