如何从远程接受所有更改?

发布于 2024-08-29 21:25:00 字数 108 浏览 2 评论 0原文

我正在做一个 pull origin some_branch ,可以看到有很多变化。最终我不介意他们是否抹掉我的一切。

我怎样才能接受它们全部或使用 mergetool 并一一合并文件?

I'm doing a pull origin some_branch and can see there are a lot of changes. Eventually I don't mind if their erase all mine.

How can I accept them all instead or using mergetool and merge files one by one?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

莫多说 2024-09-05 21:25:00

只是:

    git clone $url

说真的!这是最好的办法。

您可以执行各种 git resetgitbranch 命令来移动引用,但唯一的目的是将您的提交保留在本地存储库中的某个位置以供将来参考。如果这是目标,只需保持整个存储库不变,然后重新克隆源。

要仅接受一个分支上的所有更改,foo:

    git checkout foo
    git fetch origin +refs/heads/foo:refs/remotes/origin/foo
    git reset refs/remotes/origin/foo

foo 现在将指向与 origin 上的 foo 相同的提交>。如果你想清除工作目录中的文件,请将 --hard 添加到 git reset 中。如果要先合并,请将 fetch 替换为 pull

您的本地存储库中可能有一堆悬而未决的提交,git 可能有一天会清理这些提交,但在一段时间内您仍然可以通过引用日志访问它们。

Just:

    git clone $url

Seriously! That's the best way.

You could do all sorts of git reset and git branch commands to move the refs, but the only purpose would be to keep your commits somewhere in your local repository for future reference. If that's the goal, just keep the whole repository as is, and re-clone the origin.

To accept all changes on just one branch, foo:

    git checkout foo
    git fetch origin +refs/heads/foo:refs/remotes/origin/foo
    git reset refs/remotes/origin/foo

foo will now point at the same commit as foo on origin. If you want to blow away the files in your working directory, add --hard to git reset. If you want to merge first, replace fetch with pull.

You may have a bunch of dangling commits in your local repo, which git may clean-up someday, but for awhile you can still access them via the reflog.

嘿看小鸭子会跑 2024-09-05 21:25:00

或者:

git status | grep "both " | cut -f2 | cut -f11 -d" " | xargs git checkout --theirs
git status | grep "both " | cut -f2 | cut -f11 -d" " | xargs git add

强制接受所有冲突的远程文件。

Or:

git status | grep "both " | cut -f2 | cut -f11 -d" " | xargs git checkout --theirs
git status | grep "both " | cut -f2 | cut -f11 -d" " | xargs git add

which forces accepting all conflicting remote files.

笑忘罢 2024-09-05 21:25:00

这是我使用的方法,看起来还可以。我有一个名为“他们的”的分支,其中包含遥控器中所有内容的新版本。名为“我们的”的版本是我基于他们很久以前的版本所做的工作,其中有太多不相关的更改,但我想保留许多添加内容(站点/所有的新子目录)。

git checkout ours
git checkout theirs -- *.php *.txt *.config modules themes includes scripts
git commit -m "New version with all new key files from 'theirs'"

只要我在第二次签出时获得正确的文件和目录列表,就应该没问题。

如果我希望历史基于“他们的”分支,我可能会想反过来做。

Here's the approach I used, which seems to be OK. I have a branch called "theirs" which contains the new version of everything in the remote. A version named "ours" is my work based on a long-ago version of theirs, which too many irrelevant changes but many additions (new subdirectories of sites/all) that I want to keep.

git checkout ours
git checkout theirs -- *.php *.txt *.config modules themes includes scripts
git commit -m "New version with all new key files from 'theirs'"

As long as I got the list of files and directories in the second checkout correct, this should be fine.

If I wanted the history to be based on the "theirs" branch I might want to do this the other way round.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文