如何让 GIT 在我的案例中发挥作用?
我有一个关于 Git 的问题。我工作的地方有 2 位开发人员:我自己和另一个人。我们都使用 Visual Studio 2008 开发 VB.NET 项目,所有代码和公司文档都存储在中央本地服务器中。
因此,目前,如果我们必须处理同一个项目,我们会将存储在 Server1:/Code
中的代码复制到本地文档文件夹中,然后告诉对方我们正在使用哪些文件,这样我们就可以不处理相同的文件。在一天结束时,我们将我们的位复制回服务器(确保我不会覆盖他的文件,反之亦然)。
我研究过 Git,它似乎可以解决“不要更改 FileA 的代码,因为我正在使用它”类型的问题,并使我们能够同时处理同一个项目:即我们都得到来自 Server1 的代码副本并进行开发,我们最终将两者合并回服务器(或者我错了?)。
现在我已经阅读了 ProGit 书中的部分内容,并且了解了添加文件和提交的内容,但不确定我们如何能够同时使用它。
这里有几个问题:
- 我将在哪里创建 Git 存储库?代码存储在
Server1/Code
中,在Code
中我们有各种项目,所以我想我必须在Server1/Code
中创建存储库? - 创建存储库后,我们如何获取存储在
Server1/Code/ProjectA
中的项目A
的副本?我们是直接复制粘贴文件夹还是使用 Git? - 因为我们每个人都会在
我的文档
中拥有自己的副本,并全天处理该副本,所以我们如何在最后合并文件以便不会丢失任何内容?假设我在 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:
- Where will I create the Git repository? The code is stored in
Server1/Code
and inCode
we have various projects so I guess I have to create the repository inServer1/Code
? - After I create the repository, how do we both get a copy of, say project
A
stored inServer1/Code/ProjectA
? Will we just copy paste the folder or use Git? - 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
鉴于 Git 的分布式特性,实际上有数百种不同的工作流程,因此这只是一个示例。
此处描述了另一个流行工作流程的示例
您将在 Server1/Code 上创建存储库:
上面将所有内容添加到存储库中(您可能想要排除某些文件,因此首先将要从存储库中排除的内容放入项目根目录下的 .gitignore 文件中)
如果您使用共享,您可以使用 git 文件模式克隆:
您通常在本地分支工作:
完成后,您可以使用 git fetch origin 查看“服务器”上发生的更改。这只会更新您对服务器上发生的情况的看法,而不会下拉更改。
当您准备好将更改推送到服务器时:
1) 提交更改
2) 将服务器上的更改下拉到本地分支:
3) 合并或变基您的功能分支到 master 的本地副本
合并:
变基:
阅读下面的答案中合并和变基之间的区别:
Git 工作流程和变基与合并questions
如果存在冲突(例如,如果您都编辑相同的表单等),git 会告诉您存在合并冲突以及要合并哪些文件。完成合并后,您需要添加合并的文件:
并提交:
最后,您将更改推送回“服务器”:
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
You would create the repository on the Server1/Code:
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)
If you use a share you can clone with git file mode:
You typically work in a local 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
2) Pull down changes on server to your local branch:
3) Merge or rebase your feature branch to local copy of master
Merge:
Rebase:
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:
And commit:
Finally you push the changes back to the "server":
如果您从源代码控制开始,我建议从 SVN 开始。这更容易。
http://www.visualsvn.com/server/ - 这将让您在几分钟内创建存储库。
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.
您将拥有三个 Git 存储库。一个中央存储库(裸),每个开发人员一个私有存储库。将中央存储库放在服务器上的某个位置,将私有副本放在硬盘驱动器上。
当您想要获取代码的副本时,可以使用
git clone
。当您想要更新代码副本时,可以使用git pull
,或者使用git fetch
后跟git merge
(这是同样的事情)。不要手动复制包含 Git 存储库的文件夹。每当您完成对项目的逻辑更改时,请将更改推送到中央存储库。如果其他开发者先推送,就会发生冲突。因此,您必须拉取其他开发人员的更改,将它们合并到您的代码中(或重新设置基准,如果您愿意),然后再次推送。如果你们都对同一段代码进行了更改,那么当您在本地计算机上进行合并时,就会出现合并冲突。您在本地解决合并问题,然后将完成的(经过测试的!)版本推送到中央服务器。
不要仅仅因为一天结束就推送到中央存储库。如果最终您进行了一半的更改,您最终将共享损坏的代码,这对您的合作伙伴没有好处。等到您完成更改后,然后推送。
作为替代方案,如果您有正在进行的工作,您可以推送到中央服务器上的单独分支。
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.
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 usegit pull
, or you usegit fetch
followed bygit merge
(which is the same thing). Don't copy a folder with a Git repository manually.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.