简体   繁体   中英

ls-remote --heads origin vs ls-remote . “refs/remotes/*”

What is the difference between

git ls-remote --heads origin

and

git ls-remote . "refs/remotes/*"

?

The --heads origin version takes a while to run, I guess it's updating the references from the origin. The . "refs/remotes/*" . "refs/remotes/*" runs instantly.

I'd like to use these lines to git grep remote heads as in the expression below. Which is the right one to use?

git grep "expression" $(git ls-remote . "refs/remotes/*" | grep -v HEAD | cut -f 2)

Is it possible that the --heads origin can return hashes which are not available locally, thus git-grep wouldn't be able to complete? In this case I guess the right one to use would be . "refs/remotes/*" . "refs/remotes/*" with a fetch all first?

In git ls-remote . "refs/remotes/*" git ls-remote . "refs/remotes/*" the dot means you query your local repository to get the data.

As you wrote if you use git ls-remote --heads origin nobody guarantees that the returned hashes will be accessible locally. So I think your git fetch and then using git ls-remote . "refs/remotes/*" git ls-remote . "refs/remotes/*" is the safest option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM