简体   繁体   English

如何在git中的两个工作目录中工作?

[英]how to work in two working directories in git?

I work in two working directories in different machines. 我在不同机器上的两个工作目录中工作。 To manage two directories I made bare repository in "my com". 为了管理两个目录,我在“ my com”中创建了裸仓库。 If I do not care each time two directories are different and bare repository would sync one of them. 如果我不在乎每次两个目录都不同,并且裸存储库将同步其中之一。 Then sometimes "git push" fails. 然后有时“ git push”失败。 At the moment I am the only one who uses two working directories. 目前,我是唯一使用两个工作目录的人。

  1. Case 1: there is no collision in the files. 情况1:文件中没有冲突。 Then it might be that 那可能就是
    "git pull" then "git push" can work. “ git pull”然后“ git push”可以工作。 Is this right? 这是正确的吗?
  2. Case 2: if the same files are modified differently in both directories, how can I deal with this problem? 情况2:如果两个目录中的相同文件的修改方式不同,该如何处理?
  3. is it better to use branch? 使用分支更好吗? then it looks difficult also to merge. 那么看起来也很难合并。

still git is not so easy to me. git对我来说仍然不是那么容易。

To start off: I would suggest going through some tutorials on how git works and how to manage remotes. 首先,我建议您阅读一些有关git如何工作以及如何管理遥控器的教程。 The official Git documentation is a good starting place. 官方的Git文档是一个很好的起点。

To give an answer: 给出答案:

Keeping both repositories in sync should be very simple. 使两个存储库保持同步应该非常简单。

For example: 例如:

If you are working on your office pc and have made some changes: 如果您正在使用办公室PC并进行了一些更改:

  1. Commit those changes 提交那些更改
  2. Do a git pull pointing to your "local" PC's remote 进行git pull指向“本地” PC的遥控器

If you are working on your local pc and have made some changes: 如果您正在使用本地PC并进行了一些更改:

  1. Commit those changes 提交那些更改
  2. Do a git pull pointing to your "server" PC's remote 进行git pull指向“服务器” PC的远程

In any case there is no need to push stuff anywhere since you are the only one working on these files. 在任何情况下,都无需将内容推送到任何地方,因为您是唯一处理这些文件的人。

Regarding conflicts: If you have changed the same file on both sides, you should know which version you want to keep and use a standard merge conflict resolution procedure. 关于冲突:如果双方都更改了相同的文件,则应该知道要保留哪个版本,并使用标准的合并冲突解决程序。

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

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