[英]Git sync with local folder - sync like
有这个主要的 git 存储库“MainRepo”
这里是新的存储库“NewRepo”
Newrepo 使用“MainRepo”文件夹的确切文件/文件夹内容/结构,git 文件夹除外。
所以基本上,将内容复制到一个新文件夹,“git it”并将其推送到一个新的远程存储库。
现在它失去了与 "NewRepo" 的联系。
但是,我想继续在 NewRepo 上工作,但也要与 OldRepo 保持同步。
时不时地,一些文件会在 OldRepo 中更改,我想将这些小更改反映到 NewRepo。
我的想法是向 NewRepo 添加一个新的远程,以 OldRepo url 或 OldRepo 的本地存储库文件夹路径为目标。
并希望合并和繁荣!
所有文件都显示为 Conflict ,而不仅仅是已更改的 3 个文件。
这种合并甚至可能吗? 我想这被命名为“交叉回购合并”。
或者此操作是否涉及同步文件夹? 而不是 git 合并。
帮助我,我非常喜欢 git,有时我的爱增加了我的期望太多,最终走上了这条无处可去的道路。
问题是 OldRepo 具有 NewRepo 不共享的历史记录,因此即使它们具有相同的文件内容,它们也被视为完全不同的存储库。 如果通过克隆 OldRepo 来创建 NewRepo,应该可以解决这个问题。
听起来这就是你想要的。
rsync
: 我可以使用任何有效的工具,但一个全git
的解决方案对我来说似乎有点过头了——或者也许我对rsync
比git
更舒服。 无论如何 - 这里有new repository "NewRepo" w/ exact files/folder content/structure of "MainRepo" folder, except git folder.
使用rsync
格式:
rsync [选项] 源目标:
使用这种方式, rsync
使目标文件夹与源文件夹同步。 以下示例中显示了重要的详细信息:
$ rsync -rptgovic --dry-run --delete --exclude=filepattern1 --exclude=filepattern2 NewRepo MainRepo
NewRepo
和MainRepo
表示为文件夹规范; 例如/home/$USER/somefoldername
或./somefoldername
取决于您的pwd
。
options
由字符串ptgovidcC
和其他rsync
指令组成
请特别注意ptgovidcC
中的i
选项和--dry-run
选项。 这些选项一起使用,允许您“练习运行”以确保您的rsync
命令选项正在执行您需要的操作。
--exclude=
选项可以根据需要重复多次,以将不需要的文件/文件夹排除在MainRepo
在上面的命令中, NewRepo
是Source , MainRepo
是Destination
当然,您应该始终咨询man rsync
以确保您的命令适合您的目标。
这与上面的练习基本相同,但现在MainRepo
是Source , NewRepo
是Destination
这些options
显然也需要更改,但再次, i
和--dry-run
选项充当您的“试验场” 。
i
输出: 这并不像第一次看到它那样难,但是这个“地图”将允许您解释rsync
采取的行动 - 或在使用--dry-run
时采取的行动:
Understanding the output of rsync --itemize-changes
As you may know the rsync's --delete options if misused could make severe damage.
To prevent this you can use the --itemize-change and the --dry-run options to figure out how the command will behave before launching the real one.
The output will be something like that:
.d..t..g... ./
.f...p.g... Something.pdf
.f.....g... md5sum-2010-02-21.txt
.f...p.g... prova.rb
.d.....g... .metadata/
.f...p.g... .metadata/.lock
.f...p.g... .metadata/.log
.f...p.g... .metadata/version.ini
>f+++++++++ Parameter_Usage.txt
Where the first field of each line tell what rsync would do to each file.
I wrote this little schema that helped me to understand this output format and I'm publishing hoping it will be useful for others.
YXcstpoguax path/to/file
|||||||||||
`----------- the type of update being done::
|||||||||| <: file is being transferred to the remote host (sent).
|||||||||| >: file is being transferred to the local host (received).
|||||||||| c: local change/creation for the item, such as:
|||||||||| - the creation of a directory
|||||||||| - the changing of a symlink,
|||||||||| - etc.
|||||||||| h: the item is a hard link to another item (requires --hard-links).
|||||||||| .: the item is not being updated (though it might have attributes that are being modified).
|||||||||| *: means that the rest of the itemized-output area contains a message (e.g. "deleting").
||||||||||
`---------- the file type:
||||||||| f for a file,
||||||||| d for a directory,
||||||||| L for a symlink,
||||||||| D for a device,
||||||||| S for a special file (e.g. named sockets and fifos).
|||||||||
`--------- c: different checksum (for regular files)
|||||||| changed value (for symlink, device, and special file)
`-------- s: Size is different
`------- t: Modification time is different
`------ p: Permission are different
`----- o: Owner is different
`---- g: Group is different
`--- u: The u slot is reserved for future use.
`-- a: The ACL information changed
此模式基于man rsync
中-i, --itemize-changes
选项的内容,组织起来便于更轻松地参考REF 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.