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.
讓我通過一個例子對此進行解釋。
Let the name of the Release branch be release and the name of the Feature branch be feature.
假設Release分支的名稱為release ,而Feature分支的名稱為feature 。
變基 (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)
第2步 (Step 2)
第三步 (Step 3)
注意事項 (Points to note)
恭喜😊 (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/
我的其他帖子 (Other Posts by Me)
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
總結
以上是生活随笔為你收集整理的git 代理 git_如何成为Git专家的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到妈妈复活了预示着什么
- 下一篇: 梦到下暴雨是什么意思