简体   繁体   English

如何在 GitHub 主存储库上获取新文件

[英]How to get new files on a GitHub master repo

I'm currently in a course where the professor intermittently releases assignments on a public repo.我目前正在上一门课程,教授间歇性地发布公共存储库上的作业。 I have this repo cloned on my computer, but I don't know how to go about getting the newly released assignments.我在我的电脑上克隆了这个 repo,但我不知道如何获取新发布的任务。

Essentially, I want to pull the new files without deleting my work on the old files which I have edited.本质上,我想提取新文件而不删除我对已编辑的旧文件所做的工作。 Do I create a fork?我要创建一个分叉吗? If so, how do I pull changes from upstream but also keep my changes?如果是这样,我如何从上游提取更改同时保留我的更改? How do I resolve the conflicts that will occur when my versions of assignments have been edited?我如何解决在我的作业版本被编辑后会发生的冲突? Etc.等等。

Any help is greatly appreciated because, as of now, I've just been moving all of my files and then completely re-downloading the updated repo.非常感谢任何帮助,因为到目前为止,我一直在移动我的所有文件,然后完全重新下载更新的存储库。

Also, I'm using GitHub desktop另外,我正在使用 GitHub 桌面

I'm unfamiliar with GitHub Desktop, but hopefully there are simple equivalents in the GUI for these commands.我不熟悉 GitHub Desktop,但希望 GUI 中有这些命令的简单等效项。 If not, you can try with a backup branch in Git Bash (the command line).如果没有,您可以尝试在 Git Bash(命令行)中使用备份分支。

First, stage and commit your changes by doing git add file1 file2 etc. followed by git commit -m "change x"首先,通过执行git add file1 file2等,然后执行git commit -m "change x"git commit -m "change x"并提交您的更改

Then, here are a few possible options to update your current branch:然后,这里有一些可能的选项来更新您当前的分支:

  • git pull origin master will first fetch the content from the remote and then merge it to your current branch. git pull origin master将首先从远程获取内容,然后将其合并到您当前的分支。 If you end up with merge conflicts, git will tell you how to proceed.如果您最终遇到合并冲突,git 会告诉您如何继续。 You can resolve conflicts in your editor or GitHub Desktop.您可以在编辑器或 GitHub Desktop 中解决冲突。 For this reason, you may end up with a merge commit.出于这个原因,您可能会以合并提交结束。
  • git pull --ff-only will do the above, but it's safer in that it won't create a merge commit. git pull --ff-only将执行上述操作,但更安全,因为它不会创建合并提交。 It only updates your local master if the history is linear and it can be fast-forwarded (hence the ff-only).如果历史是线性的并且可以快进(因此只有 ff),它只会更新您的本地主节点。
  • You can also try rebasing to update your branch, which will replay your changes on top of the master history.您还可以尝试重新定位以更新您的分支,这将在主历史记录之上重播您的更改。 This makes your commits linear and thus very neat, but remember that you should not rebase public history (eg if you're working with someone else on a branch).这使得你的提交线性的,因此很整齐,但要记住,你应该变基公众历史(例如,如果你与别人的一个分支工作)。 Didn't go into too much detail about this because I think it may be a little overkill if you don't care about commit history.没有对此进行过多详细说明,因为我认为如果您不关心提交历史记录可能有点矫枉过正。

When in doubt, create a backup branch of your current branch with git checkout -b my-backup before trying anything :)如有疑问,请在尝试任何操作之前使用git checkout -b my-backup创建当前分支的备份分支:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM