如何使用git跟踪另一个目录中的更改? [英] How to use git to track changes in another directory?

查看:80
本文介绍了如何使用git跟踪另一个目录中的更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个可以访问代码但无法将版本控制添加到源目录本身的项目中. (主要开发人员拥有自己的源代码控制,但由于此处与之无关的原因,它无法访问/可理解/等.)

I'm working on a project where I have access to the code but can't add version control to the source directory itself. (The main developer has his own source control, but it's not accessible/comprehensible/etc. for reasons not relevant here.)

为了保持理智,并跟踪其他开发人员所做的任何更改,我想设置某种版本控制系统. (自VSS进入黑暗时代以来,Git是我使用过的唯一版本控制系统,所以我可能会用到它.)

To keep my sanity, as well as to track any changes the other developer makes, I'd like to have some kind of version control system set up. (Git is the only version control system I've used since the dark days of VSS, so that's probably what I'll use.)

我当前的计划是镜像现有代码库并在本地初始化git.但是当其他开发人员进行更改时,我需要能够将我的本地副本与实际源进行比较.

My current plan is to mirror the existing codebase and initialize git locally. But I'll need to be able to compare my local copy to the actual source when the other developer makes changes.

我的问题:

  1. 这是一个合理的策略吗?
  2. 如果是这样,我应该使用git init --bare还是仅使用git init进行设置?
  3. 如何将本地副本与实际来源进行比较? diff -qNr source/ local-source/? git diff --no-index source/ local-source/?还有吗?
  1. Is this a reasonable strategy?
  2. If so, should I set it up with git init --bare or just git init?
  3. How should I compare my local copy with the actual source? diff -qNr source/ local-source/? git diff --no-index source/ local-source/? Something else?

推荐答案

首先,有一点背景知识.

First, a bit of background.

在Git中,这些概念完全分开了:

In Git, these concepts are cleanly separated:

  • Git存储库:包含Git的数据
  • 工作树:您实际工作的文件系统中的目录树

当您使用git init /some/path创建本地Git存储库时,会在/some/path/.git上创建一个Git存储库,并且当您在/some/path及以下版本中运行Git命令时,Git会找到该存储库,并假定工作树位于/some/path.

When you create a local Git repository with git init /some/path, it creates a Git repository at /some/path/.git, and when you run Git commands inside /some/path and below, Git finds the repository, and assumes the work tree at /some/path.

现在就您的情况:

我正在一个可以访问代码但无法将版本控制添加到源目录本身的项目中.

I'm working on a project where I have access to the code but can't add version control to the source directory itself.

一个有趣的选择是在源目录本身之外创建一个Git存储库,并相应地设置GIT_DIR(回购)和GIT_WORK_TREE(工作树)变量. 例如,如果源目录位于/srv/project,则可以执行以下操作:

An interesting option for you can be to create a Git repository outside the source directory itself, and set the GIT_DIR (the repo) and GIT_WORK_TREE (the work tree) variables accordingly. For example, if the source directory is at /srv/project, you could do this:

git init --bare /my/projects/repo.git
export GIT_TREE=/my/projects/repo.git
export GIT_WORK_TREE=/srv/project

然后,您可以cd /srv/project并运行Git命令,就像在/srv/project中具有常规Git项目(在/srv/project/.git中具有Git存储库)一样.您可以照常使用Git命令,所有存储库操作都将完成到/my/projects/repo.git.

Then you can cd /srv/project and run Git commands, as if you had a regular Git project in /srv/project (with a Git repository in /srv/project/.git). You can use Git commands as usual, and all the repository operations will be done to /my/projects/repo.git.

在真实的Git存储库中,您可以将此另一个存储库用作远程仓库,并使用Gi​​t操作与您自己的分支进行比较.

In your real Git repository you could use this other repo as a remote, and use Git operations to make comparisons with your own branches.

我希望这会有所帮助.

这篇关于如何使用git跟踪另一个目录中的更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆