我分叉了一个项目,进行了更改,并创建了一个被接受的拉取请求。新的提交后来被添加到存储库中。我怎样才能把这些承诺交给我?
当前回答
克隆分叉存储库后,转到克隆所在的目录路径和GitBash终端中的几行。
$ 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
你很好去那里。主存储库中所有更新的更改都将被推送到您的fork存储库中。
“fetch”命令对于保持项目中的最新状态是必不可少的:只有在执行“gitfetch”时,您才会被告知同事对远程服务器所做的更改。
您仍然可以访问此处进行进一步查询
其他回答
保持分叉存储库始终保持永久更新有两个主要方面。
1.从fork master创建分支并在那里进行更改。
因此,当您的PullRequest被接受时,您可以安全地删除分支,因为当您使用上游更新它时,您贡献的代码将保存在分叉存储库的主库中。这样,您的主机将始终处于干净状态,以便创建新的分支以进行另一个更改。
2.为fork master创建一个计划作业,以便自动进行更新。
这可以用cron完成。下面是一个示例代码,如果您在linux中执行此操作。
$ crontab -e
将此代码放在crontab文件中,以每小时执行一次作业。
0 * * * * sh ~/cron.sh
然后创建cron.sh脚本文件,并与ssh代理和/或预期的git交互,如下所示
#!/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>:master相等。
遵循以下步骤。我试过了,它帮了我。
签出到您的分支机构
语法:gitbranchyourDevelopmentBranch示例:git checkout master
拉源存储库分支以获取最新代码
语法:git pullhttps://github.com/tastejs/awesome-app-ideas主人示例:git pullhttps://github.com/ORIGINAL_OWNER/ORIGINAL_REPO.git分支名称
如果您设置了上游。用gitremote-v检查一下,这就足够了。
git fetch upstream
git checkout master
git merge --no-edit upstream/master
git push
Android Studio现在已经学会了使用GitHub fork存储库(您甚至不必通过控制台命令添加“上游”远程存储库)。
打开菜单VCS→ Git公司
并注意最后两个弹出菜单项:
重新使用我的GitHub分叉创建拉取请求
试试看。我使用第一个来同步本地存储库。无论如何,在您单击“Rebase my GitHub fork”后,可以在Android Studio中访问父远程存储库(“上游”)的分支,您将能够轻松地使用它们进行操作。
(我使用带有“Git集成”和“GitHub”插件的Android Studio 3.0。)
$ git remote add upstream https://github.com/....
$ git pull upstream main
$ git push
推荐文章
- 在GitHub上有一个公共回购的私人分支?
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- 只用GitHub动作在特定分支上运行作业
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 是否有一个链接到GitHub下载文件的最新版本的存储库?
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别
- GitHub -致命:无法读取用户名https://github.com':没有这样的文件或目录
- 撤消git平分错误
- 使用.gitconfig配置diff工具
- Github:我能看到回购的下载数量吗?