Py学习  »  Git

Github:这个分支是X提交的[duplicate]

Rajiv Ranjan Singh • 4 年前 • 1130 次点击  

我最近主持了一个项目,并应用了几个修复程序。然后我创建了一个请求,然后被接受。

几天后,另一个投稿人又做了一个改动。所以我的叉子里没有零钱。

我怎样才能把零钱放进叉子里?当我有进一步的更改要贡献时,是否需要删除并重新创建我的fork?或者有更新按钮?

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/53040
 
1130 次点击  
文章 [ 20 ]  |  最新文章 4 年前
Saurabh P Bhandari
Reply   •   1 楼
Saurabh P Bhandari    4 年前

我想补充一下 @krlmlr's answer .

master feature 做些改变。

pull.yml )为了 Pull app ( 在功能分支中

version: "1"
rules:
  - base: feature
    upstream: master
    mergeMethod: merge
  - base: master
    upstream: parent_repo:master
    mergeMethod: hardreset

这使 与父回购最新的分叉回购分支。它保持了 通过 主人 通过合并分支回购的分支。这假设 特征

这里两个 mergemethods 一个是在玩 hardreset 主人 分叉回购与父回购的分支,另一种方法是 merge 特征 由于在中强制同步而完成的分支和更改 主人 分支。如果发生合并冲突,拉取应用程序将允许您在拉取请求期间选择下一个操作过程。

您可以阅读基本和高级配置以及各种 合并方法 here

我当前在分叉回购中使用此配置 here 以确保请求增强 here

Chetabahana
Reply   •   2 楼
Chetabahana    4 年前

保持一个分叉的存储库总是永久更新有两件主要的事情。

从叉子主人那里 .

所以当你 接受后,您可以安全地删除分支,因为当您使用上游更新分支时,您贡献的代码将位于分叉存储库的主控中。通过这个你的主人将永远在干净的条件下创建一个新的分支做另一个改变。

2。创建计划作业 让叉子主人 自动更新 .

cron . 这里是一个例子代码,如果你在linux中做的话。

$ crontab -e

把这个密码写在 crontab file 按小时执行工作。

0 * * * * sh ~/cron.sh

cron.sh 脚本文件和 git interaction 具有 ssh-agent expect 如下所示

#!/bin/sh
WORKDIR=/path/to/your/dir   
REPOSITORY=<name of your repo>
MASTER="git@github.com:<username>/$REPOSITORY.git"   
UPSTREAM=git@github.com:<upstream>/<name of the repo>.git  

cd $WORKDIR && rm -rf $REPOSITORY
eval `ssh-agent` && expect ~/.ssh/agent && ssh-add -l
git clone $MASTER && cd $REPOSITORY && git checkout master
git remote add upstream $UPSTREAM && git fetch --prune upstream
if [ `git rev-list HEAD...upstream/master --count` -eq 0 ]
then
    echo "all the same, do nothing"
else
    echo "update exist, do rebase!"
    git reset --hard upstream/master
    git push origin master --force
fi
cd $WORKDIR && rm -rf $REPOSITORY
eval `ssh-agent -k`

这根树枝与 <upstream> .

enter image description here

itsmysterybox s0nicYouth
Reply   •   3 楼
itsmysterybox s0nicYouth    5 年前

这取决于存储库的大小和分叉方式。

如果它是一个相当大的存储库,您可能希望用一种特殊的方式来管理它(例如删除历史记录)。基本上,您可以得到当前版本和上游版本之间的差异,提交它们,然后选择返回主版本。

尝试阅读 this one . 它描述了如何处理大型Git存储库,以及如何使用最新的更改将其上游。

prosti
Reply   •   4 楼
prosti    4 年前

git remote -v ,这样就足够了。

git fetch upstream
git checkout master
git merge --no-edit upstream/master
git push
Prateek Chanda
Reply   •   5 楼
Prateek Chanda    6 年前

克隆了分叉存储库后,转到克隆所在的目录路径和Git Bash终端中的几行。

$ cd project-name

$ git remote add upstream https://github.com/user-name/project-name.git
 # Adding the upstream -> the main repo with which you wanna sync

$ git remote -v # you will see the upstream here 

$ git checkout master # see if you are already on master branch

$ git fetch upstream

“fetch”命令对于在项目中保持最新状态是必不可少的:只有在执行“git fetch”时,才会通知您同事推送到远程服务器的更改。

你还可以去 here 供进一步查询

Peter Mortensen alexshr
Reply   •   6 楼
Peter Mortensen alexshr    6 年前

Android Studio现在已经学会了使用GitHub fork存储库(您甚至不必通过控制台命令添加“上游”远程存储库)。

打开菜单 风投 吉特

注意最后两个弹出菜单项:

  • 让我的GitHub叉子后退

试试看。我使用第一个来同步本地存储库。不管怎样,在点击“Rebase my GitHub fork”之后,来自父远程存储库(“upstream”)的分支将可以在Android Studio中访问,并且您将能够轻松地使用它们。

(我使用Android Studio 3.0和“Git集成”和“GitHub”插件。)

Enter image description here

krlmlr
Reply   •   7 楼
krlmlr    4 年前

"Pull" app 是一个自动设置和忘记的解决方案。它会将fork的默认分支与上游存储库同步。

访问URL,单击绿色的“Install”按钮并选择要启用自动同步的存储库。

Thomas Guyot-Sionnest
Reply   •   8 楼
Thomas Guyot-Sionnest    5 年前

作为这个答案的补充,我正在寻找一种方法来更新我的克隆repo的所有远程分支( )从 上游 一气呵成。我就是这样做的。

上游 远程指向源存储库(其中 从中派生)并已将其与 git fetch upstream .

然后运行:

for branch in $(git ls-remote --heads upstream|sed 's#^.*refs/heads/##'); do git push origin refs/remotes/upstream/$branch:refs/heads/$branch; done

此命令的第一部分列出 上游 refs/heads/ 分支名称前缀。

然后,对于每个分支,它都会推送 上游 远程跟踪分支( refs/remotes/upstream/<branch> 在本地端)直接到上的远程分支 起源 ( refs/heads/<branch> 在远端)。

这些分支同步命令中的任何一个都可能失败,原因有二:或者 分支已被重写,或者您已将该分支上的提交推送到您的分支上。在第一种情况下,如果你没有把任何东西放在叉子上的树枝上,用力推是安全的(加上 -f型 开关;即。 git push -f 上游 .

R.Bravo
Reply   •   9 楼
R.Bravo    6 年前

我用这一行更新分叉回购协议:

git pull https://github.com/forkuser/forkedrepo.git branch

如果您不想将另一个远程端点添加到项目中,请使用此选项,其他解决方案已在此处发布。

Peter Mortensen alexshr
Reply   •   10 楼
Peter Mortensen alexshr    8 年前

遵循以下步骤。我试过了,它帮了我。

结帐到您的分行

语法: 吉特分行你的发展分行
切换到主分支

语法: https://github.com/tastejs/awesome-app-ideas 主人
吉特拉力 https://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git 分行名称

Peter Mortensen alexshr
Reply   •   11 楼
Peter Mortensen alexshr    6 年前

实际上,可以通过浏览器中上游的任何提交在fork中创建分支:

Enter image description here

它是如何工作的(只是猜测,我不知道GitHub究竟是如何工作的):forks共享对象存储和使用 namespaces 以分离用户的引用。因此,即使叉叉不存在,也可以通过叉来访问所有提交。

Shital Shah
Reply   •   12 楼
Shital Shah    4 年前

如果您使用的是GitHub for Windows或Mac,那么现在他们有一个一键更新分叉的功能:

  1. 在UI中选择存储库。
Lucero
Reply   •   13 楼
Lucero    7 年前

截至本答复之日,GitHub尚未( or shall I say no longer? support@github.com 加入你的投票。

https://upriver.github.io/

来源如下: https://github.com/upriver/upriver.github.io

Slion
Reply   •   14 楼
Slion    4 年前

如果,像我一样,你 ,你真的应该这样做,你可以这样做。

git remote add upstream https://github.com/whoever/whatever.git

然后,每当您想赶上上游存储库主分支时,您需要:

git checkout master
git pull upstream master

假设你从来没有对主人自己做出任何承诺,你应该已经做了。现在您可以将本地主机推送到您的源远程GitHub fork。您还可以在您现在最新的本地主机上重新调整您的开发分支。

git pull上游主机 .

Benny Neugebauer
Reply   •   15 楼
Benny Neugebauer    7 年前

你的叉子是“原点”,而你的储存库是“上游”。

git clone git@github.com:your_name/project_name.git
cd project_name

如果已给出,则需要按以下顺序继续:

  1. 将“上游”添加到克隆存储库(“源”)中:

    git remote add upstream git@github.com:original_author/project_name.git
    
  2. 从“上游”获取提交(和分支):

    git fetch upstream
    
  3. 切换到叉的“主”分支(“原点”):

    git checkout master
    
  4. 保存“主”分支的更改:

    git stash
    
  5. 将“上游”的“主”分支更改合并到“源”的“主”分支:

    git merge upstream/master
    
  6. 解决合并冲突(如果有)并提交合并

    git commit -am "Merged from upstream"
    
  7. 把零钱推到你的叉子上

    git push
    
  8. 把你藏起来的零钱拿回来(如果有的话)

    git stash pop
    
  9. 你完了!祝贺 你!

GitHub还提供了有关此主题的说明: Syncing a fork

Peter Mortensen alexshr
Reply   •   16 楼
Peter Mortensen alexshr    8 年前

https://github.com/isaacs/github/issues/121

注意:由于功能请求是非官方的,所以最好联系 support@github.com 添加对要实现的此类功能的支持。上面的非官方特性请求可以用作对正在实现的这个特性感兴趣的数量的证据。

Peter Mortensen alexshr
Reply   •   17 楼
Peter Mortensen alexshr    8 年前

很多答案最后都会转移你的叉子 一次承诺 here 哪个会 .

  1. 将目录更改为本地存储库。

    • 如果你不是,切换到主分支 git checkout master
  2. 将父存储库添加为远程存储库, git remote add upstream <repo-location>

  3. git fetch upstream
  4. 发行 git rebase upstream/master

    • 在此阶段,您将通过键入 git status
  5. 发行 git push origin master

step 3 .

Peter Mortensen alexshr
Reply   •   18 楼
Peter Mortensen alexshr    8 年前

这是GitHub的官方文件 Syncing a fork :

设置

在同步之前,需要添加指向上游存储库的远程。你可能是在最初用叉子叉的时候做的。

$ git remote -v
# List the current remotes
origin  https://github.com/user/repo.git (fetch)
origin  https://github.com/user/repo.git (push)

$ git remote add upstream https://github.com/otheruser/repo.git
# Set a new remote

$ git remote -v
# Verify new remote
origin    https://github.com/user/repo.git (fetch)
origin    https://github.com/user/repo.git (push)
upstream  https://github.com/otheruser/repo.git (fetch)
upstream  https://github.com/otheruser/repo.git (push)

同步

将存储库与上游同步需要两个步骤:首先必须从远程获取,然后必须将所需的分支合并到本地分支。

提取

$ git fetch upstream
# Grab the upstream remote's branches
remote: Counting objects: 75, done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 62 (delta 27), reused 44 (delta 9)
Unpacking objects: 100% (62/62), done.
From https://github.com/otheruser/repo
 * [new branch]      master     -> upstream/master

我们现在将上游的主分支存储在本地分支upstream/master中

$ git branch -va
# List all local and remote-tracking branches
* master                  a422352 My local commit
  remotes/origin/HEAD     -> origin/master
  remotes/origin/master   a422352 My local commit
  remotes/upstream/master 5fdff0f Some upstream commit

现在我们已经获取了上游存储库,我们希望将其更改合并到本地分支中。这将使该分支与上游同步,而不会丢失本地更改。

$ git checkout master
# Check out our local master branch
Switched to branch 'master'

$ git merge upstream/master
# Merge upstream's master into our own
Updating a422352..5fdff0f
Fast-forward
 README                    |    9 -------
 README.md                 |    7 ++++++
 2 files changed, 7 insertions(+), 9 deletions(-)
 delete mode 100644 README
 create mode 100644 README.md

$ git merge upstream/master
Updating 34e91da..16c56ad
Fast-forward
 README.md                 |    5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

提示:如果要更新GitHub上的存储库,请按照说明进行操作 here

MD XF lobzik
Reply   •   19 楼
MD XF lobzik    6 年前

但是 这将导致一个肮脏的提交历史。

  1. 在GitHub上打开叉子。
  2. 拉取请求 .
  3. 点击 . 默认情况下,GitHub会将原始的和fork进行比较,如果没有做任何更改,就不应该有任何要比较的内容。
  4. 点击 切换底座 底叉 放下你的叉子 到上游去。现在,GitHub将把您的fork与原来的进行比较,您将看到所有最新的更改。 enter image description here
  5. 创建拉取请求 并为请求分配一个可预测的名称(例如。, Update from original ).
  6. 向下滚动至 ,但现在不要单击任何内容。

现在您有三个选项,但每个选项都会导致提交历史记录不干净。

  1. 默认设置将创建一个丑陋的合并提交。
  2. 如果单击下拉列表并选择“压缩并合并”,则所有介入的提交都将压缩为一个提交。这通常是你不想要的。
  3. 如果你点击 重新定位和合并 This branch is X commits ahead, Y commits behind <original fork> .

所以是的,您可以使用GitHub web UI更新回购的上游,但这样做会玷污您的提交历史。坚持 the command line 相反-很容易。

NearHuscarl Mark Longair
Reply   •   20 楼
NearHuscarl Mark Longair    6 年前

在分叉存储库的本地克隆中,可以将原始GitHub存储库添加为“远程”。(“Remotes”类似于存储库url的昵称- origin ,然后您可以从上游存储库中获取所有分支,并重新调整您的工作以继续处理上游版本。就命令而言,可能是:

# Add the remote, call it "upstream":

git remote add upstream https://github.com/whoever/whatever.git

# Fetch all the branches of that remote into remote-tracking branches,
# such as upstream/master:

git fetch upstream

# Make sure that you're on your master branch:

git checkout master

# Rewrite your master branch so that any commits of yours that
# aren't already in upstream/master are replayed on top of that
# other branch:

git rebase upstream/master

git merge upstream/master . 然而,为了使进一步的拉取请求尽可能干净,最好是重新定位。


upstream/master 可能需要强制推送才能将其推送到GitHub上自己的分叉存储库。你可以这样做:

git push -f origin master

你只需要使用 -f 在你重新定位后的第一次。