简体   繁体   English

在点对点时尚中使用有什么问题吗?

[英]anything wrong using to use in a peer-to-peer-Fashion?

foreword;-): Most people (including me) work with git in a client-server mindset I think („there's this remote repo on the dedicated server, from which you pull and push and not touch otherwise...“) I recall however, that git is basically absolute peer-to-peer, there is not truly a central server.前言;-):我认为大多数人(包括我在内)都以客户端-服务器的心态使用 git(“专用服务器上有这个远程仓库,你可以从中拉出并推送而不是触摸......”)我记得但是, git基本上是绝对点对点的,没有真正的中央服务器。

So, here's my question:所以,这是我的问题:

Are there any problems to have one git repo my machine ( ~/frank/repo ), and one on my “household” fileshare ( smb://myshare/somewhere ) connecting them mutually to each other as remote repo and work on either one?有一个 git 回购我的机器( ~/frank/repo我的“家庭”文件共享( smb://myshare/somewhere )有一个问题吗? ?

  • The benefit being, that at home several PCs in the LAN could directly work on that fileshare server and/while when I am on the road, I will work on my laptop.好处是,在家中局域网中的几台 PC 可以直接在该文件共享服务器上工作,和/而当我在路上时,我将在我的笔记本电脑上工作。
  • Doing the pulling/rebasing next time I hit home.下次我回家时进行拉动/变基。 So yeah, neither side can push, only commit while away, but not a problem for me.所以是的,任何一方都不能推动,只能在离开时提交,但对我来说不是问题。
  • I simply want to avoid a third git repository (the classic „server“).我只是想避免第三个 git 存储库(经典的“服务器”)。
  • both btw being “non-bare” repos (as in working repos), not running a git server/daemon on any port.顺便说一句,两者都是“非裸”存储库(如在工作存储库中),不在任何端口上运行 git 服务器/守护程序。 Truly just a fileshare...真的只是一个文件共享...

purpose:目的:

I am not doing source code work in this scenario, only „document shuffling“, so now branching or major merge conflicts to be expected.在这种情况下,我没有做源代码工作,只是“文档改组”,所以现在可以预期分支或主要合并冲突。 But I do want to have some basic versioning and security against accidental deletion, and a bit of journaling info (who added when what), thus rsync , xcopy , will not suit my needs...但是我确实想要一些基本的版本控制和安全性以防止意外删除,以及一些日志信息(谁添加了什么时间),因此rsyncxcopy不适合我的需要......


I have some past experience with a local bare repo I used to add as second remote (besides github), to push against when trying out things.我过去在本地仓库方面有一些经验,我曾经将其添加为第二个远程(除了 github),以便在尝试时反对。 No server/daemon/thread involved back then, too.那时也没有涉及服务器/守护进程/线程。 The only thing I am essentially about to change is to use a „non-bare“ this time and also work in there,to)我基本上要改变的唯一一件事是这次使用“非裸”并在那里工作)

AFAIK, you can't push to a checked-out branch of a non-bare repository. AFAIK,您不能推送到非裸存储库的签出分支。 But if you use different branches on each side, and sync them when needed, it can be possible I think.但是,如果您在每一侧使用不同的分支,并在需要时同步它们,我认为这是可能的。

I, well, looked rather thoroughly into the issue.我,嗯,相当彻底地研究了这个问题。 @phd and @Özgür-murat-sağdıçoğlu gave great hints,. @phd 和 @Özgür-murat-sağdıçoğlu 给出了很好的提示。 receive.denyCurrentBranch is the key! receive.denyCurrentBranch是关键!

A good recipe to build up a „tandem repo“ (just two wheels, both usable:) and sync the two without manual intervention.建立一个“串联回购”(只有两个轮子,两个都可用:)并在没有人工干预的情况下同步两者的好方法。

( Note: None of this is suitable for any source code work, just for keeping a mostly growing tree of eg scanned documents in exactly two places...) 注意:这些都不适合任何源代码工作,只是为了在两个地方保留大部分增长的例如扫描文档的树......)

creation创建

A) "Local" on Laptop ( "server" this is pushed to, itself cannot push (no reamote))

mkcd /home/frank/docs
git init --initial-branch=master --shared=all

# the most important thing! ↓↓↓
git config --local receive.denyCurrentBranch updateInstead

# (you could also take just any other file)
code -r .gitignore
git add .gitignore
git commit -m 0


B) "Share"

cd /share/docs
git clone /home/frank/docs .
# ↑ doing it like this and in this order saves the add remote, etc connecting pains

syncing同步

cd $localDir
git add . && git commit -m ""
(no pushing possible here)

cd $shareDir
git add . && git commit -m ""
git pull --rebase -X theirs
git push

(yes, you could wash away changes on local by this, but they are preserved with the first commit hence restorable, if need be.) (是的,您可以通过此方法清除本地更改,但它们会在第一次提交时保留,因此可以恢复,如果需要的话。)

The whole sync thing also goes nicely into a git alias like git sync .整个同步也很好地融入了git别名,例如git sync


Adding some sanity checks and smoke testing, this is my git alias for a fully unattend git sync :添加一些健全性检查和烟雾测试,这是我的git 别名,用于完全无人值守的git sync

# backup of final stable version, including prependd commit comment
# usage:
#       git sync
#       git sync Some stuff going on here
#       git sync 'This+that with special chars like plus'
#
# must be called from within repo, but doesn't matter which side
[alias]
  share = "!                                                                             \
    fail() {                                                                             \
      echo \"\\e[91;48;5;52mfail: $1 ✗✗✗\\e[0m – exiting.\"; exit;                       \
    };                                                                                   \
    addAndCommit() {                                                                     \
      git add .;                                                                         \
      git status;                                                                        \
      [ $? -eq 0 ] || fail 'git status not 0';                                           \
      message=\"$1: $(git status --porcelain | wc -l) Files: \";                         \
      message=\"$message$(git status --porcelain |  sed -re 's/^\\s?(M|A)\\s\\s?/\\1 /'  \
      | awk '{ printf(\"%s, \", $0) }'| cut -c -120)\";                                  \
      git commit -m \"$message\";                                                        \
    };                                                                                   \
                                                                                         \
                                                                                         \
    f() {                                                                                \
    _local='/home/frank/docs';                                                           \
    _share='/share/docs';                                                                \
    local message='';                                                                    \
                                                                                         \
    [ -z \"${1}\" ] || message=\"$1: \";                                                 \
    echo \"\ndir and sanity checks -----------------------------\";                      \
                                                                                         \
    [ -f $_share/.gitalias ] || fail 'smoke test failed: $_share/.gitalias';             \
    [ -f $_share/docsnotes.md ] || fail 'smoke test failed: $_share/docsnotes.md';       \
    [ -f $_local/.gitalias ] || fail 'smoke test failed: $_local/.gitalias';             \
    [ -f $_local/docsnotes.md ] || fail 'smoke test failed local : $_local/docsnotes.md';\
                                                                                         \
    echo \"\nLOCAL part $(pwd) ---------------------------------\";                      \
    echo \"${message}LOCAL changes\" ;                                                   \
    cd $_local;                                                                          \
    addAndCommit \"${message}LOCAL changes\";                                            \
                                                                                         \
    echo \"\nSHARE part $(pwd) ---------------------------------\";                      \
    cd $_share;                                                                          \
    addAndCommit \"${message}SHARE changes\";                                            \
    git pull --rebase -X theirs --autostash;                                             \
    git push;                                                                            \
    echo \"\n\\e[92mdone\\e[0m\";                                                        \
  }; f \"$*\""

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

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