簡體   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