GIT: should i ever use?

Git has the --force flag in many operations, but when I use them, I feel a little strange. Like ignoring warning messages in my code.

For example, I just wanted to disable the file and did the following:

 git rm --cached myfile.ext 

Git complained about the error:

the following file contains content other than the file and HEAD

I really don't care about this error and it doesn't seem to be a problem. I just want to leave my code as it is, but disable the file. The --force flag just solved this problem.

My question is about best practices, since I could not find any information about this issue. should i use force flags in git commands or is it bad practice >?

UPDATE

I found this question of mine and had some idea that mine is useful to everyone who is interested.

force flag is similar to the yes/no view of the git dialog box (or any similar software). For example, when doing something that could lead to a crash or damage, we usually get a yes/no dialog. So the git equivalent of yes is equal to --force , which answers my question that using the force flag is a normal procedure.

+7
git
source share
2 answers

--force does not mean --force chance and trying something that is likely to go wrong, but to ensure that the action is aware of potential conflicts. Therefore, I agree that using --force not a bad practice.

You often need to do just that: rewrite some verification that the git command is in place so that you don't do something stupid. If you pay attention to warnings and know that the command will succeed, there is nothing wrong with using force . See the docs (or git help pages on the command line) to see what is overwritten for each command.

Another use case is to avoid confirmation prompts when running a command from a script where you do not want or cannot handle user interaction.

+6
source share

First, for non-stationary use , you must do git reset -- file .

Secondly, I am sure that using --force not a bad practice.
One common example is that you want to add a file to the source element that is part of the ignored files (declared in .gitignore )

 git add --force -- aFile 

Do not forget that some of the same commands (for example, git add ) have a preview mode or dry ( -n ). Another good practice is to test the command with this -n option.

+3
source share

All Articles