主頁 > 資料庫 > GitHub級聯主分支更改而不覆寫客戶端自定義

GitHub級聯主分支更改而不覆寫客戶端自定義

2022-01-10 00:24:50 資料庫

我有一個保存在 Github 中的 Larave 專案。它的主要分支叫做core.

我有一個客戶需要對這個專案進行一些修改。所以我已經克隆了這個 repo 并為客戶設定了它。然后我為他做了一些改變。更改包括 - 一些額外的資料庫欄位、不同的發票格式和一些邏輯更改。

我們經常對core存盤庫進行錯誤修復和更改如何在不覆寫我們為客戶所做的定制的情況下降低客戶專案的這些更改?

我看著分支和合并。但這不會被合并。由于我為客戶所做的更改不是暫時的。它是永久性的。我們將同時運行該專案的多個版本。但是當我們在核心中進行更新時。我們希望它向下級聯。我應該使用什么結構?

我試過了,Pull但它覆寫了我為客戶所做的事情。

uj5u.com熱心網友回復:

這不是——或者至少不應該是——關于 Git 的問題,而是關于如何構建自己的系統以支持可配置客戶端的問題。但是既然你問的是Git,那么讓我們看看 Git 對git merge. (此外,關于如何構建軟體的問題通常“太大”并且對 StackOverflow 來說沒有重點;考慮一下姊妹網站之一,例如SoftwareEngineering。)

請記住,git pull字面意思是:

  1. 運行git fetch,然后
  2. 默認情況下,運行第二個 Git 命令git merge

第一個步驟- git fetch-obtains從其他一些Git倉庫新的提交:在這種情況下,錯誤修復和改變一些庫中,您控制或使用。第二個步驟,你可以選擇git rebase來代替git merge,但目標的第二個步驟是一樣的無論哪種方式,具有作為其目標,利用所獲得的新的提交第一步驟。我們通過結合作業來做到這一點

git merge命令是組合在多個不同的提交字串中完成的作業的主要方式。git rebase相反,命令會重復挑選現有的提交,目的是“改進”每個提交;每個cherry-pick都是一種特殊的merge形式,所以最后你還是要理解merging。因此,此時正確的介紹是合并。如果您還不太熟悉 Git 提交是什么以及為您做了什么,那么您現在應該去閱讀它

現在,鑒于我們有一些構成圖表的提交集,我們可以很容易地進入這樣的情況:

          I--J   <-- branch1 (HEAD)
         /
...--G--H
         \
          K--L   <-- branch2

也就是說,我們branch1使用 commit “on” branch J其他人向我們提供了我們K-L現在使用名稱branch2(或者可能是origin/branch2,但branch2為了簡單起見我畫了這個)的提交。

雖然每個提交都有每個檔案的完整快照,但兩個分支顯然會在 commit 處收斂H也就是說,當我們從當前最新的 commit 開始向后作業時J,我們會逐步 commit I, then H, then G,依此類推。同時,如果我們從他們最近一次提交的時間向后作業L,我們將逐步提交K,然后H,然后G,等等。這意味著提交H共享的——它在兩個分支上,連同它的所有祖先——我們可以很容易地選擇它作為最好的共享提交,因為根據定義它是最新的共享提交(所有其他共享提交必須早于H)。

Git 的合并操作將使用由提交的存在形成的提交圖自動找到提交(HGit 稱之為合并基礎)我們所要做的就是告訴 Git:

  • 查看我們當前的提交H
  • 看看提交L
  • 找到合并基地,并開始合并程序。

我們通過運行git merge branch2or 來做到這一點任何允許 Git 定位提交的東西在這里就足夠了:我們不必使用分支名稱。我們通常做的使用分支的名字,因為這是最簡單的我們,但所有的Git需要的是找到一種方法:它的作品了,其余自身。git merge hash-of-LLL

Git 如何執行合并操作

找到合并基礎提交后H,Git 現在已準備好執行合并操作。這包括:

  • 將每個檔案與H中的每個檔案進行比較J,以查看我們在每個檔案中所做的更改(如果有的話);
  • 將每個檔案與H中的每個檔案進行比較L,以查看它們在每個檔案中所做的更改(如果有的話);
  • 當 Git 處理它時,它會弄清楚我們是否重命名、添加或洗掉了任何整個檔案,對它們也是如此。通常所有三個提交都具有相同的檔案集,因此這種額外的皺紋不會引起任何胃灼熱,對于這個特定的答案,我們將忽略這種可能性。

對于許多合并中的許多檔案,沒有人改變任何東西這使得合并檔案變得微不足道:三個提交中的三個版本中的任何一個都可以,因為所有三個版本都是相同的。(Git 的自動檔案重復資料洗掉在這里非常方便:Git 立即知道檔案是否在兩個或三個提交中重復。)

對于許多合并中的其他檔案,要么我們更改了某些內容,要么他們更改了某些內容,但是如果我們更改了某些內容,它們不會觸及該檔案,反之亦然。同樣,這使得合并該檔案變得微不足道:Git 只需要采用任何一個更改的. 但是,我們可以將其視為第三種也是最復雜的情??況的特例。

Last, we have the third and most complicated case: both we and they made changes to the same file. What Git does for this case is straightforward and not clever at all: Git simply combines the changes. If we deleted line 3 and they didn't do anything to line 3, Git will delete line 3. If they added a line between lines 10 and 11 and we didn't, Git will take their added line. Git repeats this process for every modification—line by line, because Git's internal git diff works on a line-by-line basis.1 As long as the changes we make to some line(s) do not touch or overlap the changes they make to other line(s), Git is able to do this line-by-line work by itself, and does so.

If Git is able to resolve all files on its own, Git will normally go on to make a new merge commit on its own as well. A merge commit is the same as any other commit: it has a unique hash ID and contains a snapshot—a copy of every file, as of the form it should have when extracted later—and some metadata. The only thing special about a merge commit is that instead of one parent commit hash ID, the metadata list of parent commits lists two parents.2 We can draw that here as:

          I--J
         /    \
...--G--H      M   <-- branch1 (HEAD)
         \    /
          K--L   <-- branch2

Note that, as usual, the current branchbranch1—now points to the new commit, and the new commit M points back to the commit you were on a moment ago, commit J, as usual. What's different about M is that it has a second parent L, indicating that this commit joins two histories: one that results from starting at J and working backwards, and one that result from starting at L and working backwards.


1Note that this means that Git is utterly unable to combine changes to binary files. If you have a conflict in a binary file, Git will refuse to help you out here.

2Technically, this is two or more, with "more" producing what Git calls an octopus merge. Octopus merges don't do anything you cannot do with ordinary merges. (In fact, except for joining up multiple branches, they do less than you can do with an ordinary merge, which is their ultimate value proposition: if you see an octopus merge in a Git history, you know that, despite the many inputs, the merge itself was simple—or as simple as it could be based on the number of inputs.)


Merge conflicts

Sometimes we and they make different changes to the same line. For instance, a line might read:

the red ball

in some file in the merge base commit H. We change this to:

the blue ball

but they change it to:

the red cube

Git has no idea how to combine these two changes. If the result should be "the blue cube", you will have to make that change yourself. Git also declares a conflict if we change two lines that "touch", even though in some cases this might not be necessary. This is based on years of experience with merge algorithms: this seems to produce the result most humans find the most pleasing, or at least, has done so historically.

In any case, Git will now take the combined changes—plus any conflicts—and apply the combined changes to the file from the merge base. That way, Git keeps our changes and adds theirs, or, depending on your point of view, keeps their changes and adds ours. (The result is the same either way.) If Git encountered nothing it declared as a merge conflict, it goes on to arrange for the combined-changes file to go into the next commit. Otherwise, Git leaves behind a mess:

  • Git's index (see this answer for more about the index AKA staging area) will contain all three versions of the file, from the merge base, the HEAD or --ours commit, and the other or --theirs commit;
  • the working tree copy of the file will contain Git's best effort at combining the changes, including conflict markers.

Your job is to come up with the correct combined file—you can do this in any way that pleases you—and then to adjust Git's index to hold the correct copy of the file. Git doesn't need the working tree copy at all, but git add tells Git: make the index version of the file match the working tree version, with the side effect of deleting from the index the extra versions that prevent committing. Most people thus mostly find it easiest to fix up the working tree copy and then run git add, or to use git mergetool, which is a command that:

  1. runs some tool of your choice to do the "fix up working tree file" step, then
  2. runs git add for you.

Note that this is really all that git mergetool does, so git mergetool does not add a lot of value. However, the process of extracting all three input files—merge base, --ours, and --theirs—is a bit tedious, and before git mergetool runs your choice of merge tool (vimdiff, kdiff3, Beyond Compare, or whatever else you may like), it automates this part of the job.

Once we've resolved all conflicts, we tell Git to finish the merge, by running either git merge --continue or git commit. Git then goes on to make merge commit M as usual.

Conclusion for real merges

In any case, we now have a complete overview of what git merge does for the case where we start with:

          I--J   <-- branch1 (HEAD)
         /
...--G--H
         \
          K--L   <-- branch2

Git will use HEAD to locate commit J, the argument to git merge to locate commit L, and the commit graph to locate the merge base commit H. Git will then diff the snapshot in H against those in J and L as needed to find changes, combine the changes, and apply the combined changes to the files from the merge base H. If the combining goes smoothly, Git will make the resulting merge commit M on its own. If not, Git will stop in the middle of the merge, force us to finish the merge—we cannot proceed without either finishing or aborting the merge, due to the messed-up state of Git's index3—and when we do finish the merge we get the same merge commit M, this time with human intervention.


3This is a real problem. There is no proper way to deliver a partial merge to someone else, making collaborative merging difficult. Fortunately, with most smaller merges, one person can do the job.


A special case

As a special case, consider what happens if we're in the following situation:

...--G--H   <-- branch1 (HEAD)
         \
          I--J   <-- branch2

Suppose we now run git merge branch2. If Git were to follow the usual rules for merges, it would:

  • locate commits H and J as ours and theirs;
  • locate the common merge base, which is commit H again;
  • diff H vs H to see what we changed;
  • diff H vs J to see what they changed;
  • combine these changes; and
  • make a new merge commit.

The result would look like this:

...--G--H------M   <-- branch1 (HEAD)
         \    /
          I--J   <-- branch2

where I've used the letter M again to stand for "merge". But: what's in the snapshot in commit M? We had Git diff commit H vs commit H to see what we changed, and by definition, if we compare H against it self, nothing changed. So Git combines our "nothing" with whatever they did—presumably, something—and the resulting files necessarily exactly match all the files in commit L.

One might legitimately wonder: Why bother? And in fact, by default, git merge does not bother. It detects that commit H is commit H and that there's therefore nothing of ours to carry forward. Instead of merging, Git does a fast-forward operation (which git merge chooses, rather cheekily, to call a "fast-forward merge" even though nothing is merged). Instead of merging, then, Git just drags the branch name branch1 "forward", like this:

...--G--H
         \
          I--J   <-- branch1 (HEAD), branch2

There's no need for the kink in the drawing any more, so we can draw this graph like this now:

...--G--H--I--J   <-- branch1 (HEAD), branch2

The fast-forward non-merge "merge" is now complete, by virtue of simply making both branch names point to commit J.

Sometimes there is nothing to do

Suppose that we have a graph that looks like this:

...--G--H   <-- branch2
         \
          I--J   <-- branch1 (HEAD)

That is, this is like the fast-forward case, except we're on the later commit J, rather than the earlier commit H. If we run git merge branch2 now, Git will say "already up to date" and quit. There's literally nothing to do: commit H is already part of our history at commit J.

These two special cases work by finding the merge base as usual: if the merge base is one of the two end-point commits, we have a special case. The special case is either "nothing to do" (the merge base is the other commit) or "fast-forward" (the merge base is not the other commit, but is our commit). So Git will always find the merge base.

The last special case

There's a final special case, which with any luck you will never encounter. Suppose we have a graph like this one:

...--o--A---M1--o--L   <-- branch1 (HEAD)
         \ /
          X
         / \
...--o--B---M2--o--R   <-- branch2

where o represents a commit (or any number of commits) that aren't interesting, and the two M commits are two merges whose input commits are A and B (plus some merge base, not shown here, that Git found automatically).

如果我們git merge branch2現在運行Land 中的作業結合起來R,則提交AB都是“同樣好的”提交作為合并基礎候選者。兩個提交都在兩個分支上,并且沒有一個“離終點更遠”(如果我們使用通常的最低公共祖先演算法,兩個提交哈希 ID 都會以未確定的順序從中出來)。

Git 有多種方法來處理這個問題,但 Git-2.34 之前的默認策略是合并合并基礎AB產生臨時提交,然后使用臨時提交作為合并基礎來合并LR. 在 Git 2.34 中,一種新演算法嘗試做與合并遞回相同的事情,但沒有那么多瘋狂和浪費精力。4 我自己還沒有研究過新演算法,因此不會在這里嘗試解釋它。


4 “正常”的非遞回合并主要發生在 Git 的索引中,作業樹檔案偶爾用于臨時存盤。2.34 之前的merge-recursive代碼使用相同的方法執行每個內部合并,merge-recursive code并從結果中逐個提交(或至少是一個樹物件),如果需要,添加到包含沖突標記的索引檔案中。這為“外部”合并提供了適當的合并基礎,但意味著合并沖突向前傳播,這意味著像 GitHub 這樣的網站不能使用此代碼。merge-ort代碼在記憶體和 Git 的索引中進行了整個合并,而不使用臨時檔案,而且——據我所知——也直接處理遞回,

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/406708.html

標籤:

上一篇:如何重寫Rebase檔案內容以更改多個提交

下一篇:解決合并中的所有索引/作業樹沖突后,`gitcommit`和`gitmerge--continue`之間的區別?

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • GPU虛擬機創建時間深度優化

    **?桔妹導讀:**GPU虛擬機實體創建速度慢是公有云面臨的普遍問題,由于通常情況下創建虛擬機屬于低頻操作而未引起業界的重視,實際生產中還是存在對GPU實體創建時間有苛刻要求的業務場景。本文將介紹滴滴云在解決該問題時的思路、方法、并展示最終的優化成果。 從公有云服務商那里購買過虛擬主機的資深用戶,一 ......

    uj5u.com 2020-09-10 06:09:13 more
  • 可編程網卡芯片在滴滴云網路的應用實踐

    **?桔妹導讀:**隨著云規模不斷擴大以及業務層面對延遲、帶寬的要求越來越高,采用DPDK 加速網路報文處理的方式在橫向縱向擴展都出現了局限性。可編程芯片成為業界熱點。本文主要講述了可編程網卡芯片在滴滴云網路中的應用實踐,遇到的問題、帶來的收益以及開源社區貢獻。 #1. 資料中心面臨的問題 隨著滴滴 ......

    uj5u.com 2020-09-10 06:10:21 more
  • 滴滴資料通道服務演進之路

    **?桔妹導讀:**滴滴資料通道引擎承載著全公司的資料同步,為下游實時和離線場景提供了必不可少的源資料。隨著任務量的不斷增加,資料通道的整體架構也隨之發生改變。本文介紹了滴滴資料通道的發展歷程,遇到的問題以及今后的規劃。 #1. 背景 資料,對于任何一家互聯網公司來說都是非常重要的資產,公司的大資料 ......

    uj5u.com 2020-09-10 06:11:05 more
  • 滴滴AI Labs斬獲國際機器翻譯大賽中譯英方向世界第三

    **桔妹導讀:**深耕人工智能領域,致力于探索AI讓出行更美好的滴滴AI Labs再次斬獲國際大獎,這次獲獎的專案是什么呢?一起來看看詳細報道吧! 近日,由國際計算語言學協會ACL(The Association for Computational Linguistics)舉辦的世界最具影響力的機器 ......

    uj5u.com 2020-09-10 06:11:29 more
  • MPP (Massively Parallel Processing)大規模并行處理

    1、什么是mpp? MPP (Massively Parallel Processing),即大規模并行處理,在資料庫非共享集群中,每個節點都有獨立的磁盤存盤系統和記憶體系統,業務資料根據資料庫模型和應用特點劃分到各個節點上,每臺資料節點通過專用網路或者商業通用網路互相連接,彼此協同計算,作為整體提供 ......

    uj5u.com 2020-09-10 06:11:41 more
  • 滴滴資料倉庫指標體系建設實踐

    **桔妹導讀:**指標體系是什么?如何使用OSM模型和AARRR模型搭建指標體系?如何統一流程、規范化、工具化管理指標體系?本文會對建設的方法論結合滴滴資料指標體系建設實踐進行解答分析。 #1. 什么是指標體系 ##1.1 指標體系定義 指標體系是將零散單點的具有相互聯系的指標,系統化的組織起來,通 ......

    uj5u.com 2020-09-10 06:12:52 more
  • 單表千萬行資料庫 LIKE 搜索優化手記

    我們經常在資料庫中使用 LIKE 運算子來完成對資料的模糊搜索,LIKE 運算子用于在 WHERE 子句中搜索列中的指定模式。 如果需要查找客戶表中所有姓氏是“張”的資料,可以使用下面的 SQL 陳述句: SELECT * FROM Customer WHERE Name LIKE '張%' 如果需要 ......

    uj5u.com 2020-09-10 06:13:25 more
  • 滴滴Ceph分布式存盤系統優化之鎖優化

    **桔妹導讀:**Ceph是國際知名的開源分布式存盤系統,在工業界和學術界都有著重要的影響。Ceph的架構和演算法設計發表在國際系統領域頂級會議OSDI、SOSP、SC等上。Ceph社區得到Red Hat、SUSE、Intel等大公司的大力支持。Ceph是國際云計算領域應用最廣泛的開源分布式存盤系統, ......

    uj5u.com 2020-09-10 06:14:51 more
  • es~通過ElasticsearchTemplate進行聚合~嵌套聚合

    之前寫過《es~通過ElasticsearchTemplate進行聚合操作》的文章,這一次主要寫一個嵌套的聚合,例如先對sex集合,再對desc聚合,最后再對age求和,共三層嵌套。 Aggregations的部分特性類似于SQL語言中的group by,avg,sum等函式,Aggregation ......

    uj5u.com 2020-09-10 06:14:59 more
  • 爬蟲日志監控 -- Elastc Stack(ELK)部署

    傻瓜式部署,只需替換IP與用戶 導讀: 現ELK四大組件分別為:Elasticsearch(核心)、logstash(處理)、filebeat(采集)、kibana(可視化) 下載均在https://www.elastic.co/cn/downloads/下tar包,各組件版本最好一致,配合fdm會 ......

    uj5u.com 2020-09-10 06:15:05 more
最新发布
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:33:24 more
  • MySQL中binlog備份腳本分享

    關于MySQL的二進制日志(binlog),我們都知道二進制日志(binlog)非常重要,尤其當你需要point to point災難恢復的時侯,所以我們要對其進行備份。關于二進制日志(binlog)的備份,可以基于flush logs方式先切換binlog,然后拷貝&壓縮到到遠程服務器或本地服務器 ......

    uj5u.com 2023-04-20 08:28:06 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:27:27 more
  • 快取與資料庫雙寫一致性幾種策略分析

    本文將對幾種快取與資料庫保證資料一致性的使用方式進行分析。為保證高并發性能,以下分析場景不考慮執行的原子性及加鎖等強一致性要求的場景,僅追求最終一致性。 ......

    uj5u.com 2023-04-20 08:26:48 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:26:35 more
  • 云時代,MySQL到ClickHouse資料同步產品對比推薦

    ClickHouse 在執行分析查詢時的速度優勢很好的彌補了MySQL的不足,但是對于很多開發者和DBA來說,如何將MySQL穩定、高效、簡單的同步到 ClickHouse 卻很困難。本文對比了 NineData、MaterializeMySQL(ClickHouse自帶)、Bifrost 三款產品... ......

    uj5u.com 2023-04-20 08:26:29 more
  • sql陳述句優化

    問題查找及措施 問題查找 需要找到具體的代碼,對其進行一對一優化,而非一直把關注點放在服務器和sql平臺 降低簡化每個事務中處理的問題,盡量不要讓一個事務拖太長的時間 例如檔案上傳時,應將檔案上傳這一步放在事務外面 微軟建議 4.啟動sql定時執行計劃 怎么啟動sqlserver代理服務-百度經驗 ......

    uj5u.com 2023-04-20 08:25:13 more
  • Redis 報”OutOfDirectMemoryError“(堆外記憶體溢位)

    Redis 報錯“OutOfDirectMemoryError(堆外記憶體溢位) ”問題如下: 一、報錯資訊: 使用 Redis 的業務介面 ,產生 OutOfDirectMemoryError(堆外記憶體溢位),如圖: 格式化后的報錯資訊: { "timestamp": "2023-04-17 22: ......

    uj5u.com 2023-04-20 08:24:54 more
  • day02-2-商鋪查詢快取

    功能02-商鋪查詢快取 3.商鋪詳情快取查詢 3.1什么是快取? 快取就是資料交換的緩沖區(稱作Cache),是存盤資料的臨時地方,一般讀寫性能較高。 快取的作用: 降低后端負載 提高讀寫效率,降低回應時間 快取的成本: 資料一致性成本 代碼維護成本 運維成本 3.2需求說明 如下,當我們點擊商店詳 ......

    uj5u.com 2023-04-20 08:24:03 more
  • day02-短信登錄

    功能實作02 2.功能01-短信登錄 2.1基于Session實作登錄 2.1.1思路分析 2.1.2代碼實作 2.1.2.1發送短信驗證碼 發送短信驗證碼: 發送驗證碼的介面為:http://127.0.0.1:8080/api/user/code?phone=xxxxx<手機號> 請求方式:PO ......

    uj5u.com 2023-04-20 08:23:11 more