git 代理 git_如何成為Git專家

git 代理 git

I made a mistake in my commit, how do I fix it ?

我在提交中犯了一個錯誤,該如何解決?

My commit history is a mess, how do I make it neater?

我的提交歷史是一團糟,我如何使其更整潔?

If you have ever had the above questions, then this post is for you. This post covers a list of topics which will make you a Git expert.

如果您曾經遇到上述問題,那么這篇文章適合您。 這篇文章涵蓋了一個主題列表,這些主題將使您成為Git專家。

If you do not know Git basics, click here to check out my blog on Git basics. It is necessary that you know basics of Git to make the best use of this article.

如果您不了解Git基礎知識, 請單擊此處查看有關Git基礎知識的博客。 為了充分利用本文,有必要了解Git的基礎知識。

我犯了一個錯誤。 我該怎么辦? (I made a mistake in my commit. What should I do?)

場景1 (Scenario 1)

Let’s say that you have committed a bunch of files and realised that the commit message you entered is actually not clear. Now you want to change the commit message. In order to do this you can use git commit --amend

假設您已經提交了一堆文件,并且意識到您輸入的提交消息實際上并不清晰。 現在您要更改提交消息。 為此,您可以使用git commit --amend

git commit --amend -m "New commit message"

方案2 (Scenario 2)

Let’s say that you wanted to commit six files but, by mistake, you end up committing only five files. You may think that you can create a new commit and add the 6th file to that commit.

假設您要提交六個文件,但是由于錯誤,您最終只能提交五個文件。 您可能認為您可以創建一個新的提交并將第六個文件添加到該提交中。

There is nothing wrong with this approach. But, to maintain a neat commit history, wouldn’t it be nicer if you could actually somehow add this file to your previous commit itself? This can be done through git commit --amend as well:

這種方法沒有錯。 但是,為了保持簡潔的提交歷史記錄,如果您實際上可以以某種方式將此文件添加到以前的提交本身中,會不會更好? 這也可以通過git commit --amend來完成:

git add file6
git commit --amend --no-edit

--no-edit means that the commit message does not change.

--no-edit表示提交消息不會更改。

場景3 (Scenario 3)

Whenever you do a commit in Git, the commit has an author name and author email tied to it. Generally, when you set up Git for the first time, you set up the author name and email. You don’t need to worry about the author details for every commit.

每當您在Git中進行提交時,該提交都會帶有作者姓名和作者電子郵件。 通常,首次設置Git時,需要設置作者姓名和電子郵件。 您無需擔心每次提交的作者詳細信息。

That said, it’s possible that for a particular project you want to use a different email ID. You need to configure the email id for that project with the command:

也就是說,對于特定項目,您可能想要使用其他電子郵件ID。 您需要使用以下命令為該項目配置電子郵件ID:

git config user.email "your email id"

Let’s say that you forgot to configure the email and already did your first commit. Amend can be used to change the author of your previous commit as well. The author of the commit can be changed using the following command:

假設您忘記配置電子郵件,并且已經進行了第一次提交。 Amend也可以用于更改您先前提交的作者。 可以使用以下命令來更改提交的作者:

git commit --amend --author "Author Name <Author Email>"

注意事項 (Point to note)

Use the amend command only in your local repository. Using amend for the remote repository can create a lot of confusion.

在本地存儲庫中使用amend命令。 對遠程存儲庫使用amend可能會造成很多混亂。

我的提交歷史是一團糟。 我該如何處理? (My Commit history is a mess. How do I handle it?)

Let’s say that you are working on a piece of code. You know that the code is going to take approximately ten days to complete. Within those ten days, the other developers will also be committing code to the remote repository.

假設您正在編寫一段代碼。 您知道該代碼大約需要十天才能完成。 在這十天內,其他開發人員還將把代碼提交到遠程存儲庫。

It is a good practise to keep your local repository code up-to-date with the code in the remote repository. This avoids a lot of merge conflicts later when you raise a pull request. So you decide that you will pull the changes from the remote repository once every two days.

這是一個很好的做法 ,讓您的本地倉庫代碼上最新與遠程存儲庫中的代碼。 這樣可以避免以后引發拉取請求時發生很多合并沖突。 因此,您決定每兩天從遠程存儲庫中提取一次更改。

Every time you pull the code from the remote repository to the local repository a new merge commit is created in your local repository. This means that your local commit history is going to have a lot of merge commits which can make things look confusing to the reviewer.

每次將代碼從遠程存儲庫拉到本地存儲庫時,都會在本地存儲庫中創建一個新的合并提交。 這意味著您的本地提交歷史記錄將包含很多合并提交,這會使審閱者感到困惑。

您如何使提交歷史看起來更整潔? (How do you make the commit history look neater?)

This is where rebase comes to the rescue.

這是底墊就派上用場了。

什么是變基? (What is rebasing?)

Let me explain this through an example.

讓我通過一個例子對此進行解釋。

  1. The Release branch has three commits: Rcommit1, Rcommit2, and Rcommit3.

    Release分支具有三個提交:Rcommit1,Rcommit2和Rcommit3。
  2. You created your Feature branch from the Release branch when it had only one commit, which is Rcommit1.

    在只有一個提交(即Rcommit1)的情況下,您從Release分支創建了Feature分支。
  3. You have added two commits to the Feature branch. They are Fcommit1 and Fcommit2.

    您已向Feature分支添加了兩個提交。 它們是Fcommit1和Fcommit2。
  4. Your goal is to get the commits from the Release branch into your Feature branch.

    您的目標是使發布從Release分支到Feature分支。
  5. You are going to use rebase to do this.

    您將使用rebase來執行此操作。
  6. Let the name of the Release branch be release and the name of the Feature branch be feature.

    假設Release分支的名稱為release ,而Feature分支的名稱為feature

  7. Rebasing can be done using the following commands:

    可以使用以下命令來完成基礎調整:
git checkout feature
git rebase release

變基 (Rebasing)

While rebasing, your goal is to ensure the Feature branch gets the latest code from the Release branch.

在重新定基時,您的目標是確保Feature分支從Release分支獲取最新代碼。

Rebasing tries to add each commit, one by one, and checks for conflicts. Does that sound confusing?

變基嘗試逐個添加每個提交,并檢查是否存在沖突。 這聽起來令人困惑嗎?

Let me explain with the help of a diagram.

讓我借助圖表進行說明。

This shows what rebasing actually does internally:

這顯示了變基在內部實際執行的操作:

第1步 (Step 1)

  1. The moment you run the command, the Feature branch is pointed to the head of Release branch.

    運行命令后,Feature分支便指向Release分支的頭部。
  2. Now the Feature branch has three commits: Rcommit1, Rcommit2, and Rcommit3.

    現在,Feature分支具有三個提交:Rcommit1,Rcommit2和Rcommit3。
  3. You may be wondering what happened to Fcommit1 and Fcommit2.

    您可能想知道Fcommit1和Fcommit2發生了什么。
  4. The commits are still there and will be used in the steps below.

    提交仍然存在,將在以下步驟中使用。

第2步 (Step 2)

  1. Now Git tries to add Fcommit1 to the Feature branch.

    現在,Git嘗試將Fcommit1添加到Feature分支。
  2. If there is no conflict Fcommit1 is added after Rcommit3

    如果沒有沖突,則在Rcommit3之后添加Fcommit1
  3. If there is a conflict, Git will notify you, and you will have to resolve the conflict manually. After the conflict is resolved use the following commands to continue rebasing

    如果存在沖突,Git將通知您,您將必須手動解決沖突。 解決沖突后,使用以下命令繼續進行基礎調整
git add fixedfile
git rebase --continue

第三步 (Step 3)

  1. Once Fcommit1 is added, Git will try to add Fcommit2.

    添加Fcommit1后,Git將嘗試添加Fcommit2。
  2. Again, if there is no conflict Fcommit2 is added after Fcommit1 and the rebase is successful.

    同樣,如果不存在沖突,則在Fcommit1之后添加Fcommit2,并且成功進行重新設置基準。
  3. If there is a conflict, Git will notify you, and you will have to resolve it manually. Use the same commands mentioned in Step 2 after resolving conflicts

    如果有沖突,Git將通知您,您必須手動解決它。 解決沖突后,請使用步驟2中提到的相同命令
  4. After the entire rebase is done, you will notice that the Feature branch has Rcommit1, Rcommit2, Rcommit3 , Fcommit1, and Fcommit2.

    完成整個基準后,您將注意到Feature分支具有Rcommit1,Rcommit2,Rcommit3,Fcommit1和Fcommit2。

注意事項 (Points to note)

  1. Both Rebase and Merge are useful in Git. One is not better than the other.

    Rebase和Merge在Git中都非常有用。 一個并不比另一個更好。
  2. In the case of a merge you will have a merge commit. In the case of a rebase there is no extra commit like a merge commit.

    在合并的情況下,您將有一個合并提交。 在進行rebase的情況下,沒有像合并提交這樣的額外提交。
  3. One best practise is to use the commands at different points. Use rebase when you are updating your local code repository with the latest code from the remote repository. Use merge when you are dealing with pull requests to merge the Feature branch back with the Release or Master branch.

    一種最佳實踐是在不同位置使用命令。 使用遠程存儲庫中的最新代碼更新本地代碼存儲庫時,請使用rebase。 處理合并請求時,請使用合并將Feature分支與Release或Master分支合并。
  4. Using Rebase alters the commit history ( it makes it neater) . But that being said, altering the commit history has it’s risks. So ensure you never use rebase on a code that is there in the remote repository. Always use rebase only to alter the commit history of your local repo code.

    使用Rebase會更改提交歷史記錄(使其更整潔)。 話雖這么說,改變提交歷史還是有風險的。 因此,請確保永遠不要在遠程存儲庫中的代碼上使用rebase。 始終僅使用rebase來更改本地存儲庫代碼的提交歷史記錄。
  5. If rebase is done to a remote repository it can create a lot of confusion since other developers will not recognise the new history.

    如果對遠程存儲庫進行了基礎更改,則可能會造成很多混亂,因為其他開發人員將無法識別新的歷史記錄。
  6. Also if rebase is done on the remote repository, it can create issues when other developers try to pull the latest code from remote repository. So I repeat again, always use rebase only for the local repository ?

    同樣,如果在遠程存儲庫上完成了重新設置基準,則當其他開發人員嘗試從遠程存儲庫中獲取最新代碼時,它也會造成問題。 所以我再說一遍,總是只對本地存儲庫使用rebase嗎?

恭喜😊 (Congrats 😊)

You are now a Git expert ?

您現在是Git專家?

In this post you have learnt about:

在這篇文章中,您了解了:

  • amending commits

    修改提交
  • rebase

    重新設定

Both of these are very useful concepts. Go explore the world of Git to learn even more.

這兩個都是非常有用的概念。 去探索Git的世界以了解更多。

關于作者 (About the author)

I love technology and follow the advancements in the field. I also like helping others with my technology knowledge.

我熱愛技術,并關注該領域的進步。 我也喜歡用我的技術知識來幫助他人。

Feel free to connect with me on my LinkedIn account https://www.linkedin.com/in/aditya1811/

隨時使用我的LinkedIn帳戶與我聯系https://www.linkedin.com/in/aditya1811/

You can also follow me on twitter https://twitter.com/adityasridhar18

您也可以在Twitter上關注我https://twitter.com/adityasridhar18

My Website: https://adityasridhar.com/

我的網站: https : //adityasridhar.com/

Best Practises while using Git

使用Git時的最佳做法

An introduction to Git

Git簡介

How to use Git efficiently

如何有效使用Git

翻譯自: https://www.freecodecamp.org/news/how-to-become-a-git-expert-e7c38bf54826/

git 代理 git

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392843.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392843.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392843.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

101與金根回顧敏捷個人:(13)敏捷個人和敏捷開發

本文更新版本已挪至 http://www.zhoujingen.cn/blog/1726.html ------------------------- 敏捷個人源于工作 自2001初成立了敏捷聯盟到現在10年的推廣&#xff0c;敏捷開發已日漸成為當前IT行業軟件開發的一種主流方法。沒有銀彈&#xff0c;任何方法都不可能解決所有問題&a…

計算機網絡選擇重傳,計算機網絡選擇重傳協議實驗報告..docx

計算機網絡選擇重傳協議實驗報告.《計算機網絡》選擇重傳協議實驗報告1.實驗內容和實驗環境描述實驗內容&#xff1a;利用所學數據鏈路層原理&#xff0c;設計一個滑動窗口協議&#xff0c;在仿真環境下編程實現有噪音信道環境下兩站點之間無差錯雙工通信。信道模型為8000bps 全…

leetcode 劍指 Offer 03. 數組中重復的數字

找出數組中重復的數字。 在一個長度為 n 的數組 nums 里的所有數字都在 0&#xff5e;n-1 的范圍內。數組中某些數字是重復的&#xff0c;但不知道有幾個數字重復了&#xff0c;也不知道每個數字重復了幾次。請找出數組中任意一個重復的數字。 示例 1&#xff1a; 輸入&…

【Maven學習】Maven打包生成包含所有依賴的jar包

http://blog.csdn.net/u013177446/article/details/54134583 ************************************************** maven打包生成的普通jar包&#xff0c;只包含該工程下源碼編譯結果&#xff0c;不包含依賴內容。同時&#xff0c;maven提供以下方式生成包含所有依賴的jar文件…

mysql 數據庫 安全_如何確保您MySQL數據庫安全

mysql 數據庫 安全我們開始之前的一些基本信息&#xff1a; (Some basic information before we get started:) Source: Center for Internet Security’s (CIS) Oracle MySQL Community Server 5.7來源&#xff1a; 互聯網安全中心(CIS)Oracle MySQL Community Server 5.7 Op…

Exchange server 2010系列教程之三 發送郵件測試

最近有些忙&#xff0c;好幾天沒有上來寫教程了&#xff0c;接著往下寫吧。就當是自己的學習筆記&#xff0c;呵呵&#xff0c;有不到之處&#xff0c;還請大家多多指教。 上一篇我們已經把服務器架設好了&#xff0c;那么我們來測試一下發送郵件。 1.首先在AD DC上面新建一個域…

如何用計算機掃描圖片變成文字,怎么掃描圖片上的文字-華為手機黑科技"文字掃描儀",3秒就能將紙質文檔轉成電子檔,牛...

現如今&#xff0c;手機已經成為我們使用率最高的電子設備之一了。手機雖小&#xff0c;但是功能可是五花八門&#xff0c;很多手機的功能&#xff0c;可能我們使用幾年&#xff0c;都沒有發現過。今天就給大家介紹華為手機中&#xff0c;非常強大的一項黑科技“文字掃描儀”。…

第一步:編輯器選擇

對于c/c的學習已經進一年的時間了&#xff0c;現在想開始好好換一個文本編輯器&#xff0c;然后慢慢的學習&#xff0c;隨著時間的增加而不斷增加。兩款頗有爭議的軟件是Vim和emacs&#xff0c;兩者之間的選擇其實對于初學者的我還是比較困難的&#xff0c;Vim在原來有點接觸過…

leetcode116. 填充每個節點的下一個右側節點指針(dfs)

代碼 /* // Definition for a Node. class Node {public int val;public Node left;public Node right;public Node next;public Node() {}public Node(int _val) {val _val;}public Node(int _val, Node _left, Node _right, Node _next) {val _val;left _left;right _ri…

react銷毀方法鉤子0_React鉤子:使用React狀態的新方法

react銷毀方法鉤子0Updated: With React 16.8, React Hooks are available in a stable release!更新&#xff1a;隨著React 16.8的發布&#xff0c; React Hooks已經發布&#xff01; Outdated: Hooks are still an experimental proposal. They’re currently in React v16.…

Linux下安全審計工具 lynis 使用說明

官網&#xff1a;https://cisofy.com/download/lynis/ 下載解壓后&#xff0c;執行./lynis -Q即可&#xff0c;稍等片刻自動生成一份檢測報告。可以根據檢測報告看哪里不足進行改進即可。 本文轉自 lirulei90 51CTO博客&#xff0c;原文鏈接&#xff1a;http://blog.51cto.com/…

課堂訓練

1.對于可能的變更是否能制定應急計劃&#xff1f; 可以制定 例如一款app的開發&#xff0c;在制作app之前會對app的功能性進行一個規劃&#xff0c;想的比較全面就能很好應對變更。 2.員工是否能夠有效地處理意料之外的工作請求&#xff1f; 能夠處理 對于工作能力極強的員工而…

Google 實用搜索技巧

孔子曰&#xff1a;“工欲善其事&#xff0c;必先利其器。居是邦也&#xff0c;是其大夫之賢者&#xff0c;友其示支仁者。”——語出《論語衛靈公》 1. Google搜索固定格式的文檔 Google支持特定格式文檔的搜索&#xff08;“filetype:”就是它的搜索語法&#xff09;&#xf…

華科的計算機和建筑學哪個強,華中科技大學和華南理工大學相比,誰更占優勢?看了也許就知道了...

大學是學生接受教育的過程中非常重要的一個階段&#xff0c;很多學生都會盡可能在高考中&#xff0c;考出更好的成績&#xff0c;爭取報考一個更好的大學。為了提升教育水平&#xff0c;我國到目前為止建設了超過3000所大學&#xff0c;其中有很多高等院校非常相似&#xff0c;…

c#+handle.exe實現升級程序在運行時自動解除文件被占用的問題

我公司最近升級程序經常報出更新失敗問題&#xff0c;究其原因&#xff0c;原來是更新時&#xff0c;他們可能又打開了正在被更新的文件&#xff0c;導致更新文件時&#xff0c;文件被其它進程占用&#xff0c;無法正常更新而報錯&#xff0c;為了解決這個問題&#xff0c;我花…

播客#50:Sacha Greif

On todays episode of the freeCodeCamp Podcast, Quincy Larson interviews Sacha Greif, a designer, developer, and prolific open source project creator.在今天的免費CodeCamp播客中&#xff0c;昆西拉爾森(Quincy Larson)采訪了設計師&#xff0c;開發人員和多產的開源…

leetcode 977. 有序數組的平方(雙指針)

給定一個按非遞減順序排序的整數數組 A&#xff0c;返回每個數字的平方組成的新數組&#xff0c;要求也按非遞減順序排序。 示例 1&#xff1a; 輸入&#xff1a;[-4,-1,0,3,10] 輸出&#xff1a;[0,1,9,16,100] 示例 2&#xff1a; 輸入&#xff1a;[-7,-3,2,3,11] 輸出&am…

Spring.net的一個小例子

入門級的Spring.net的例子&#xff0c;比Spring.net帶的例子還要簡單。容易上手。下載地址&#xff1a;http://files.cnblogs.com/elevenWolf/SpringTest.rar轉載于:https://www.cnblogs.com/martinxj/archive/2005/07/18/195105.html

使用JavaScript的Platformer游戲教程

Learn how to create a platformer game using vanilla JavaScript.了解如何使用香草JavaScript創建平臺游戲。 This tutorial starts with teaching how to organize the code using the Model, View, Controller (MVC) strategy and the principles of Object Oriented Prog…

leetcode 52. N皇后 II(回溯)

n 皇后問題研究的是如何將 n 個皇后放置在 nn 的棋盤上&#xff0c;并且使皇后彼此之間不能相互攻擊。 給定一個整數 n&#xff0c;返回 n 皇后不同的解決方案的數量。 示例: 輸入: 4 輸出: 2 解釋: 4 皇后問題存在如下兩個不同的解法。 [ [".Q…", // 解法 1 “……