Answer the question
In order to leave comments, you need to log in
What does the "--" flag mean in many git operations?
I constantly notice that it is present in many basic operations, but I still do not understand the meaning.
For example:git reset -- file1.txt dev/nginx_vhosts/file2.txt
Answer the question
In order to leave comments, you need to log in
By a fairly common convention, all parameters after the double bar are considered positional (most often these are file names). git
adheres to this agreement.
For example, someone accidentally created a file named -n
, and you want to display all the files in the folder with the commandcat
$ ls -l
total 8
-rw-rw-r-- 1 lynn lynn 6 Apr 19 12:34 file1
-rw-rw-r-- 1 lynn lynn 6 Apr 19 12:33 -n
cat *
, it will turn out strange: $ cat *
1 file1
can file1 -n
, i.e. output a file file1
with line numbers. $ cat -- *
file1
a
b
c
cat -- file1 -n
, but by convention, --
there can be no command keys after, only file names. git
there is an even stricter convention, according to which the parameters after --
can only be paths. test
and a branch test
, then it will be like this:$ git branch
* master
test
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: test
no changes added to commit (use "git add" and/or "git commit -a")
$ git reset test
fatal: ambiguous argument 'test': both revision and filename
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
$ git reset -- test
Unstaged changes after reset:
M test
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question