push my local files to my server with git without pulling/cloning files from server

huangapple go评论91阅读模式
英文:

push my local files to my server with git without pulling/cloning files from server

问题

这可能有点混乱,但我会尽量简单地解释一下 push my local files to my server with git without pulling/cloning files from server

好的,我在我的服务器上有一些文件,它们正在使用中,我对它们做了一些更改。

现在我想让我的开发者(他在另一台机器上工作)能够从他的本地推送到服务器上。

我在我的服务器上添加了一个git仓库,以便通过在hooks中添加一个post-receive文件并将以下代码添加到其中,从而实现从本地直接推送到服务器。

git --work-tree=/root/server/resources --git-dir=/root/git/server.git checkout master -f

但现在的问题是,我的系统上的文件与服务器上的文件不同步,我希望能够从我的本地推送到服务器(我的开发者也可以),所以我需要将服务器上的git与我的本地以及开发者的本地进行同步,而不需要重新克隆,因为项目大小很大(2GB)。

我可以将服务器上的文件推送到GitHub或GitLab,但问题是我必须从我的本地再次推送,这对我来说是不可能的。

我需要以某种方式将本地机器上的重复文件与服务器同步,并只克隆更改部分。

英文:

This might be confusing but I will try to explain it as simple as possible push my local files to my server with git without pulling/cloning files from server

ok I have some files on my server and it's being used right now and I made some changes on them.

now I want to make it possible for my developer which is using another machine to push from his local to the server.

I added a git repo on my server to make it possible to push from local to the server directly by adding a post-receive file in hooks with this code in it

git --work-tree=/root/server/resources --git-dir=/root/git/server.git checkout master -f

but the problem now is my files on my sytem are not synced with the server and I want to be able to push from my local to the server (my developer too) so I need to sync the git from server with my local and my developer local without cloning again because project size is big (2gb)

I can push the server files on github or gitlab but problem is I have to push again from my local which is not possible for me

I need to somehow sync the duplicate files on local machine with server and just clone the changes.

答案1

得分: 1

假设我正确理解了你的问题,你可以首先在本地运行 git status 来检查本地和远程服务器之间的当前情况。要开始同步,你可以运行 git fetch --prune 来获取服务器存储库的所有更改,并在同步远程引用与本地时清理旧引用(请查看 git-scm 文档中关于 prune 选项的说明)。

之后,你需要将本地分支与远程分支同步,因此你应该将本地分支重置以与远程分支对齐。

git reset --hard origin/master

这将重置你的本地分支与远程分支(在这种情况下是 'master')对齐。

警告:这将删除本地未提交的更改和未推送的提交

你还可以使用 git clean -f -dgit clean -f -d -x 来清理未跟踪和被忽略的文件,只需在实际运行清理之前执行干运行(使用 -n 标志)以查看会发生什么。

注意:如果出现任何混乱,你可以使用 git reflog 来恢复已删除的提交、分支或撤消重新基础或合并错误。

英文:

Assuming I understood your issue correctly, you can first run git status on local to check for the current situation between your local and remote server. To start syncing, you can run git fetch --prune to get all the changes from the server repo and clean the old references on local while syncing up the remote references on the server with local (check out git-scm doc on the prune option).

After that you need to sync your local branch with the remote one, so you should reset your local branch to align with the remote one.

git reset --hard origin/master

This resets your local branch with the remote branch ('master' in this case)

Warning: this will remove any changes that weren't committed and commits that weren't pushed from local

you can also clean untracked and ignored files with git clean -f -d and git clean -f -d -x respectively. just make sure to execute a dry-run (with '-n' flag) to see what would happen before actually running the clean up.

Note: In case of any mess-up, you can use git reflog to recover any deleted commits, branches or undo rebase or merge mistakes.

huangapple
  • 本文由 发表于 2023年7月24日 18:35:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76753635.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定