繁体   English   中英

提交到GitHub

[英]Commits to GitHub

当我想要进行更改并将它们提交到GitHub时,将使用以下工作流程:

$ git checkout -b NewBranch
# Creates a new branch from origin/master for working on a specific feature and immediately switches to that branch. At this point you can add the feature you want.

$ git commit -a -m 'added a new function'
    # Commits the changes to the NewBranch

$ git checkout master
$ git merge NewBranch
    # Merging the changes we did in NewBranch with origin/master
$ git branch -d NewBranch
    # Deletes the NewBranch as it’s no longer needed
Pushing changes to remote repository
$ git push origin
    # Pushes all the changes from the master branch to the origin repository

此时,我访问GitHub网站并转到我的在线存储库,即原始项目的分支。 我单击“ 新建请求” ,添加一些文本,所有更改均在请求中向原始所有者提出。

到这里,一切都按预期进行。 但是,在这一点上,当我在客户端上本地进行其他更改并执行另一个git push origin ,这些更改也将立即合并/添加到先前进行的同一Pull Request中。

如何避免将这些新更改添加到原始“拉取请求”中? 然后,我只想在我的个人分支中在线,而不是在原始存储库中。

您将有两种解决方案:

  1. 当您发出请求请求时,首先合并请求请求。 合并后,您只能在本地开始工作。

  2. 推送代码后,您可以创建新分支,并从旧分支中提取代码,然后开始进行处理。 因此,当您要推送代码时,它将推送到您的新分支,它将不会合并到先前的请求中。 要合并此请求,您需要创建新的请求请求。

感谢@oruckdeschel的最终最佳解决方案是将我的工作方式更改为以下步骤:

设置'git push'

$ git config --global push.default simple

Simple将当前分支推送到其上游分支,但是如果上游分支的名称与本地名称不同,则拒绝推送(这是git未来版本的默认设置)

新增功能

$ git checkout -b NewBranch

(为每个功能)创建一个新分支,并立即切换到该分支。 此时,您可以对文件进行特定于功能的更改。

$ git commit -a -m 'Added a new feature’

将更改提交到NewBranch

$ git push

将当前分支及其更改推送到GitHub。

Go to the GitHub webpage of your fork and click ‘Compare & Pull Request’:
- Base fork: OriginalAuthor/Project  - Base: Master --- Head fork: Me/Project  - Compare: NewBranch 

发出请求请求后,对该分支的所有新更改也将自动添加到同一请求请求中

$ git checkout master
$ git merge NewBranch

将我们在NewBranch中所做的更改与master合并。 master始终是私有的,不会在GitHub的Pull Request中共享

$ git push -d origin NewBranch
$ git branch -d NewBranch

仅当接受请求请求时删除分支

希望这可能会帮助其他人使用GitHub。

感谢你们的大力帮助!

我的评论为答案:

我通常在分支机构工作有点不同。 我承诺进入分支机构后再推动。 因此,该分支将降落在github中。 在那里您可以创建请求请求。 合并对主服务器的更改(不删除分支),然后在主服务器上执行“私有”更改。 每当您推送到“拉出请求”分支时,提交都会自动添加到拉取请求中。

暂无
暂无

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

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