Git 强制完全同步到 master

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2906130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:26:29  来源:igfitidea点击:

Git force complete sync to master

svngitgit-svn

提问by Jesse Vogt

My workplace uses Subversion for source control so I have been playing around with git-svn for the advantages of my own branches, commit as often as I want without touching the main repo, etc.

我的工作场所使用 Subversion 进行源代码控制,所以我一直在使用 git-svn 来发挥我自己分支的优势,在不触及主存储库的情况下随时提交,等等。

Since my git svn checkout is local, I have cloned it to a network share as well to act as a backup. My thinking is that if my desktop takes a dump I will at least have the repo on the network share to get changes that I have not had a chance to dcommit yet.

由于我的 git svn checkout 是本地的,我已经将它克隆到网络共享以及作为备份。我的想法是,如果我的桌面进行转储,我至少会在网络共享上拥有 repo,以获取我还没有机会提交的更改。

My workflow is to work from the desktop, make changes, commit, etc. At the end of the day I want to update the repo on the network share with all of my current changes. I had setup the repo on the network share using git clone repo_on_my_desktopand then updating the repo on the network share with git pull origin master. The problem that I am running into is when I used do a git rebaseto squish multiple commits prior to dcommitting to the main svn repository. When I do this, I get merge conflicts on the repo on the network share when I try to backup at night.

我的工作流程是从桌面工作,进行更改,提交等。在一天结束时,我想用我当前的所有更改更新网络共享上的存储库。我设置使用网络共享的回购git clone repo_on_my_desktop,然后更新与网络共享回购git pull origin master。我遇到的问题是,git rebase在 dcommitting 到主 svn 存储库之前,我使用 do a来压缩多个提交。当我这样做时,当我尝试在晚上备份时,我会在网络共享上的 repo 上遇到合并冲突。

Is there a way to simply sync entirely with the repository on my desktop without doing a new git cloneeach night?

有没有一种方法可以简单地与我桌面上的存储库完全同步,而无需git clone每晚都做一个新的?

采纳答案by VonC

Two comments:

两条评论:

1/ I would recommend having either bare repoor a bundle(one file, easier to move around) for your network share

1/ 我建议为您的网络共享使用裸仓库捆绑包(一个文件,更容易移动)

2/ I would rather add network_repo as a remote to your desktop repo and push from there (git push --force network_repo master): you stay in your working repo.

2/ 我宁愿将 network_repo 作为远程添加到您的桌面存储库并从那里推送(git push --force network_repo master):您留在您的工作存储库中。

回答by hasen

You shouldn't be doing a rebase if you intend to pull from another repo.

如果您打算从另一个 repo 中提取,则不应该进行 rebase。

If you don't mind overriding changes in your network share, you can do this:

如果您不介意覆盖网络共享中的更改,您可以这样做:

git fetch origin master
git reset --hard origin/master

This will reset the local master to the origin master.

这会将本地 master 重置为 origin master。

Warning: this is a hardreset, it will lose all your changes (committed* or not).

警告:这是一个重置,它将丢失您的所有更改(已提交或未提交)。

But I'm assuming you don't really have any changes there, and it's mostly just a backup.

但我假设你那里没有任何变化,它主要只是一个备份。

* Note: technically speaking, committed changes are not lost until they expire from the reflog, but for all intents and purposes, they're effectively lost.

* 注意:从技术上讲,提交的更改在从 reflog 过期之前不会丢失,但出于所有意图和目的,它们实际上已丢失。