Prevent file overwriting with git

my company recently started using Git for version control, and because of the incompetence of the encoders - like me and my boss: -P - we have really good spaghetti files that are overwritten here and there. <sh> Is there a way to mark certain files as “untouchable”, so if, when updating a branch from another or not (not) overwriting the file or not updating at all?
Thanks in advance.

+2
source share
5 answers

You can do exactly what you ask with hooks, but I don’t know if your real problem solves.

If it is as simple as your executable files to be launched, it is easy: never pull / merge / reinstall with uncommitted changes. Always commit before entering any other code.

+3
source

You can add a file called .gitignore. Any file name that matches the regular expression in this file will be ignored by git.

So, I usually start with something like:

*.log *~ conf/* 

Change the taste.

+3
source

In general, Git tries to avoid overwriting modified files by using checkout to move from branch to branch. That is, if the file has not been modified and Git needs to be changed, the file will change (the previous contents of the file still exist in the previous branch). If the file has been modified and Git does not need to be changed, the contents of the file will be saved. If the file has been modified and Git wants to change it, you will be notified that local changes conflict with changing the branch and Git will refuse to switch branches.

To understand why your files were overwritten unexpectedly, we probably need more information about what you did.

+1
source

Getting Git requires very specific steps to throw out the information, and even then it does not overwrite the information. Thus, the situation may not be what you think.

Think of the Git repository as a transactional database of your source code. Depending on your settings and settings, this may be a hidden database, so all you see is a working directory.

The fact is that Git uses this working directory in the local file system as a browser in the database. This “opinion” may change, and the record of all your transactions (commits) is still in the repo, unchanged.

Thus, the working directory that you see will change according to what you called (see, as a rule, a branch). Even copies of files that open in a text editor can change, which really disgusted me the first time I noticed it.

You can throw away the previous work, for example:
1. git reset HEAD~2 , which discards your last two commits or
2. checkout -f , which discards unmanaged changes in your working directory (irrevocably if they were not git add ed) before moving to another branch ('view')
but you cannot inadvertently rewrite information without receiving at least a warning. In most cases, the information is still in the repo until garbage is collected, usually after more than 30 days.

As Greg said, we need more information to know for sure.

+1
source

It looks like you want to stop git from tracking "untouchable" files. This is done using git rm command .

 git rm <file> 

If this is what you want, use the -dry-run switch to see what happens. If you are sure that you want to delete files, you can use the -cached switch to prevent local files from being deleted.

Of course, you will have to manually add files to future branches, which is probably not a good idea.

0
source

All Articles