简体   繁体   English

Git-添加所有远程跟踪的本地文件

[英]Git - add all local files that are tracked remotely

I have an (outdated) copy of a git repository, without any git tracking. 我有一个git存储库的(过时的)副本,没有任何git跟踪。 (no .git folder at all) (根本没有.git文件夹)

I want to initialize git , connect it to the remote repository, and temporarily add the files in the local copy so I can compare them to the files in the remote. 我想初始化git ,将其连接到远程存储库,并临时将文件添加到本地副本中,以便可以将它们与远程文件进行比较。

However, I don't want to compare files that don't exist in the remote environment. 不过,我并不想比较没有在远程环境中存在的文件。

Thanks to the answer I got to my last question , this is what I've got so far: 多亏了我对最后一个问题的回答 ,这是我到目前为止所得到的:

git init
git remote add origin {origin_URL}
git fetch --all
# stage files
git add .
git --no-pager diff -R origin/master --numstat
# unstage them
git reset

However, the out-of-date local copy of the repo has tons of "extra" files (that I don't care about), making it difficult to see just what files have changed. 但是,过时的本地回购副本包含大量的“额外”文件(我不在乎),这使得很难看到更改过的文件。

Is there a way to add only files that are tracked remotely, (ignoring files that only exist locally) without adding all the files / directories that I want to ignore to .gitignore ? 有没有一种方法可以添加远程跟踪的文件(忽略仅本地存在的文件),而不将我要忽略的所有文件/目录添加到.gitignore

I found the answer in the manual : 我在手册中找到了答案:

git --no-pager diff -R origin/master --numstat --diff-filter=d

the --diff-filter=d excludes files that were "deleted". --diff-filter=d排除“删除”的文件。 Since I'm doing the diff in reverse in this case, that means files that exist locally but not remotely. 由于在这种情况下我要反向进行比较,因此这意味着文件位于本地但不位于远程。 Exactly what I was looking for. 正是我想要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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