如何让 GIT 在我的案例中发挥作用?

发布于 2025-01-07 14:20:05 字数 998 浏览 0 评论 0原文

我有一个关于 Git 的问题。我工作的地方有 2 位开发人员:我自己和另一个人。我们都使用 Visual Studio 2008 开发 VB.NET 项目,所有代码和公司文档都存储在中央本地服务器中。

因此,目前,如果我们必须处理同一个项目,我们会将存储在 Server1:/Code 中的代码复制到本地文档文件夹中,然后告诉对方我们正在使用哪些文件,这样我们就可以不处理相同的文件。在一天结束时,我们将我们的位复制回服务器(确保我不会覆盖他的文件,反之亦然)。

我研究过 Git,它似乎可以解决“不要更改 FileA 的代码,因为我正在使用它”类型的问题,并使我们能够同时处理同一个项目:即我们都得到来自 Server1 的代码副本并进行开发,我们最终将两者合并回服务器(或者我错了?)。

现在我已经阅读了 ProGit 书中的部分内容,并且了解了添加文件和提交的内容,但不确定我们如何能够同时使用它。

这里有几个问题:

  1. 我将在哪里创建 Git 存储库?代码存储在 Server1/Code 中,在 Code 中我们有各种项目,所以我想我必须在 Server1/Code 中创建存储库?
  2. 创建存储库后,我们如何获取存储在 Server1/Code/ProjectA 中的项目 A 的副本?我们是直接复制粘贴文件夹还是使用 Git?
  3. 因为我们每个人都会在我的文档中拥有自己的副本,并全天处理该副本,所以我们如何在最后合并文件以便不会丢失任何内容?假设我在 VS2008 中创建了一个新表单,其中包含一个按钮和其后面的一些代码,而另一个人在其他地方更改了一些代码?或者例如,我向 FormA 添加一些代码,他也向 FormA 添加一些代码?最后我们如何合并它们?

正如我所说,我已经在家里的电脑上安装了 git 和 git 扩展,并试用了它,并且不介意使用 git bash (命令行)或 git GUI。

任何帮助将不胜感激。

I have a question regarding Git. The place where I work has 2 developers: myself and another guy. We both developing a VB.NET project using Visual Studio 2008 and all the code and the company documents are all stored in a central local server.

So at the moment if both of us have to work on the same project we copy the code stored in Server1:/Code to our local documents folder and just tell each other what files we are using so we are not working on the same files. At the end of the day we copy our bits back to the server (making sure I don't override his files and vice versa).

I have looked into Git and it seems that it will solve this "Don't change the code of FileA because I am using it" type of problem and will enable us to work on the same project at the same time: i.e we both get a copy of the code from Server1 and develop and we merge both at the end of the day back to the server (or am I wrong?).

Now I have read parts of ProGit book and I get the bit where you add files and do commits but am not sure how both of us will be able to use it at once.

A few questions here:

  1. Where will I create the Git repository? The code is stored in Server1/Code and in Code we have various projects so I guess I have to create the repository in Server1/Code?
  2. After I create the repository, how do we both get a copy of, say project A stored in Server1/Code/ProjectA? Will we just copy paste the folder or use Git?
  3. Because each of us will have our own copy in My Documents and work on that copy throughout the day, how will we merge the files at the end so that nothing gets lost? Let's say I have created a new Form in VS2008 with a button and some code behind it and the other guy has changed some code somewhere else? Or for example, I add some code to FormA and he adds some code to FormA too? How do we merge them at the end?

As I said I have installed git and git extensions on my pc at home and had a play with it and do not mind using either git bash (command line) or git GUI.

Any help will be greatly appreciated guys.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苦行僧 2025-01-14 14:20:05

鉴于 Git 的分布式特性,实际上有数百种不同的工作流程,因此这只是一个示例。

此处描述了另一个流行工作流程的示例

我将在哪里创建 GIT 存储库?代码存储在
Server1/Code 和 Code 中我们有各种项目,所以我想我必须
在 Server1/Code 中创建存储库?

您将在 Server1/Code 上创建存储库:

git init && 
git add . && 
git commit -am "Initial commit"

上面将所有内容添加到存储库中(您可能想要排除某些文件,因此首先将要从存储库中排除的内容放入项目根目录下的 .gitignore 文件中)

创建存储库后,我们如何获得副本,比如说
项目 A 存储在 Server1/Code/ProjectA 中?我们只需复制粘贴
文件夹或使用 GIT?

如果您使用共享,您可以使用 git 文件模式克隆:

git clone file:////<host>/<share>/<path>

因为我们每个人都会在“我的文档”中拥有自己的副本并致力于
一整天的复制,最后我们如何合并文件
这样就不会丢失任何东西吗?假设我创建了一个新表单
VS2008 有一个按钮和后面的一些代码,另一个人有
在其他地方更改了一些代码?或者例如,我添加一些代码
FormA 并且他也向 FormA 添加了一些代码?我们如何将它们合并到
结束?

您通常在本地分支工作:

git checkout -b local_feature_branch

完成后,您可以使用 git fetch origin 查看“服务器”上发生的更改。这只会更新您对服务器上发生的情况的看法,而不会下拉更改。

当您准备好将更改推送到服务器时:

1) 提交更改

git commit -am "My changes"

2) 将服务器上的更改下拉到本地分支:

git checkout master && git pull origin master

3) 合并或变基您的功能分支到 master 的本地副本

合并:

git merge local_feature_branch

变基:

git checkout local_feature_branch && 
git rebase master && 
git checkout master && 
git merge local_feature_branch

阅读下面的答案中合并和变基之间的区别:

Git 工作流程和变基与合并questions

如果存在冲突(例如,如果您都编辑相同的表单等),git 会告诉您存在合并冲突以及要合并哪些文件。完成合并后,您需要添加合并的文件:

git add merged_file

并提交:

git commit -am "Merged with master"

最后,您将更改推送回“服务器”:

git push origin master

Given the distributed nature of Git, there are literally hundreds of different workflows, so this is only one example.

Another example of a popular workflow is described here

Where will I create the GIT repository? The code is stored in
Server1/Code and in Code we have various projects so I guess I have to
create the repository in Server1/Code?

You would create the repository on the Server1/Code:

git init && 
git add . && 
git commit -am "Initial commit"

The above adds everything to the repository (you maybe want to exclude some files, so put what you want to exclude from the repository in a .gitignore file in the root of the project first)

After I create the repository, how do we both get a copy of, say
project A stored in Server1/Code/ProjectA? Will we just copy paste the
folder or use GIT?

If you use a share you can clone with git file mode:

git clone file:////<host>/<share>/<path>

Because each of us will have our own copy in My Documents and work on
that copy throughout the day, how will we merge the files at the end
so that nothing gets lost? Let's say I have created a new Form in
VS2008 with a button and some code behind it and the other guy has
changed some code somewhere else? Or for example, I add some code to
FormA and he adds some code to FormA too? How do we merge them at the
end?

You typically work in a local branch:

git checkout -b local_feature_branch

When you are done, you can see what changed on the "server" using git fetch origin. This will only update your view of what happened on the server, it will not pull down the changes.

When you are ready to push your changes up to the server:

1) Commit changes

git commit -am "My changes"

2) Pull down changes on server to your local branch:

git checkout master && git pull origin master

3) Merge or rebase your feature branch to local copy of master

Merge:

git merge local_feature_branch

Rebase:

git checkout local_feature_branch && 
git rebase master && 
git checkout master && 
git merge local_feature_branch

Read up on the difference between merge and rebase in answer below:

Git workflow and rebase vs merge questions

If there is a conflict (for example if you both edit the same form etc.), git tells you that there was a merge conflict and what files to merge. After doing the merge you do add the merged file:

git add merged_file

And commit:

git commit -am "Merged with master"

Finally you push the changes back to the "server":

git push origin master
别想她 2025-01-14 14:20:05

如果您从源代码控制开始,我建议从 SVN 开始。这更容易。

http://www.visualsvn.com/server/ - 这将让您在几分钟内创建存储库。

  1. 您可以在任何您喜欢的地方创建存储库。然后将已有的代码放入存储库中。
  2. 之后安装 Tortoise SVN 和/或 SVNMonitor 以从存储库更新/推送到存储库。您第一次从存储库中签出代码。它将下载所有代码到您指定的目录。
  3. 使用 SVN 您还可以锁定文件进行编辑。这样其他人就无法同时编辑它。但这不是建议的工作方式。一般来说,合并不是问题,因为大多数时候你会处理其他事情,而不是你的同事。但是,如果您编辑同一个文件,第一个人将成功签入,而另一个人将收到有人更改了该文件的消息。然后,他必须使用存储库中的版本更新他的文件版本,并进行合并和签入。但合并通常是自动的。

If you are starting with source control I would suggest starting with SVN. It's just easier.

http://www.visualsvn.com/server/ - this will let you create repository in minutes.

  1. You can create repository wherever you like. Then put code you already have in the repository.
  2. After that install Tortoise SVN and/or SVNMonitor to update from/push to repository. For the first time you checkout code from the repository. It will download all the code to directory you specify.
  3. Using SVN you can also lock file for editing. That way other person won't be able to edit it at the same time. But this is not suggested way of working. Generally merges are not a problem because most of the time you will be working on other stuff then your coworker. But if it happens that you edit the same file the first person will succeed at the checkin and the other person will receive message that someone changed that file. Then he will have to update his version of file with the version from the repository and do the merge and checkin. But often merges are automatic.
梦境 2025-01-14 14:20:05
  1. 您将拥有三个 Git 存储库。一个中央存储库(裸),每个开发人员一个私有存储库。将中央存储库放在服务器上的某个位置,将私有副本放在硬盘驱动器上。

  2. 当您想要获取代码的副本时,可以使用git clone。当您想要更新代码副本时,可以使用 git pull,或者使用 git fetch 后跟 git merge (这是同样的事情)。不要手动复制包含 Git 存储库的文件夹。

  3. 每当您完成对项目的逻辑更改时,请将更改推送到中央存储库。如果其他开发者先推送,就会发生冲突。因此,您必须拉取其他开发人员的更改,将它们合并到您的代码中(或重新设置基准,如果您愿意),然后再次推送。如果你们都对同一段代码进行了更改,那么当您在本地计算机上进行合并时,就会出现合并冲突。您在本地解决合并问题,然后将完成的(经过测试的!)版本推送到中央服务器。

不要仅仅因为一天结束就推送到中央存储库。如果最终您进行了一半的更改,您最终将共享损坏的代码,这对您的合作伙伴没有好处。等到您完成更改后,然后推送。

作为替代方案,如果您有正在进行的工作,您可以推送到中央服务器上的单独分支。

  1. You will have three Git repositories. One central repository (bare), and one private one for each developer. Put the central repository on a server somewhere, put the private copies on your hard drives.

  2. When you want to get a copy of the code, you use git clone. When you want to update your copy of the code, you use git pull, or you use git fetch followed by git merge (which is the same thing). Don't copy a folder with a Git repository manually.

  3. Whenever you finish making a logical change to the project, push the change to the central repository. If the other developer has pushed first, you will get a conflict. So you'll have to pull the other developer's changes, merge them into your code (or rebase, if you want), and push again. If you both make changes to the same piece of code, you'll get a merge conflict when you merge on your local machine. You resolve the merge locally and then push the finished (tested!) version to the central server.

Don't push to the central repository just because it's the end of the day. If at the end of the day you're halfway through a change, you'll end up sharing broken code which is no good for your partner. Wait until you are finished with your change and then push.

As an alternative, you can push to a separate branch on the central server if you've got something in-progress.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文