git 命令git 地址_這是我上周使用的所有Git命令及其作用。

git 命令git 地址

by Sam Corcos

由Sam Corcos

這是我上周使用的所有Git命令及其作用。 (Here are all the Git commands I used last week, and what they do.)

Like most newbies, I started out searching StackOverflow for Git commands, then copy-pasting answers, without really understanding what they did.

像大多數新手一樣,我開始在StackOverflow上搜索Git命令,然后復制粘貼答案,而不真正了解它們的作用。

I remember thinking, “Wouldn’t it be nice if there were a list of the most common Git commands along with an explanation as to why they are useful?”

我記得在想 “如果有最常用的Git命令列表以及它們為什么有用的解釋,這會很好嗎?”

Well, here I am years later to compile such a list, and lay out some best practices that even intermediate-advanced developers should find useful.

好吧,幾年后,我在這里編譯了這樣一個列表,并列出了一些最佳實踐,即使是中高級的開發人員也應該找到有用的。

To keep things practical, I’m basing this list off of the actual Git commands I used over the past week.

為了使事情變得實用,我以上周使用的實際Git命令為基礎列出了該列表。

Almost every developer uses Git, and most likely GitHub. But the average developer probably only uses these three commands 99% of the time:

幾乎每個開發人員都使用Git,最有可能使用GitHub。 但是一般的開發人員可能僅在99%的時間中使用以下三個命令:

git add --allgit commit -am "<message>"git push origin master

That’s all well and good when you’re working on a one-person team, a hackathon, or a throw-away app, but when stability and maintenance start to become a priority, cleaning up commits, sticking to a branching strategy, and writing coherent commit messages becomes important.

當您在一個人團隊,黑客馬拉松或一次性應用中工作時,這一切都很好,但是當穩定和維護開始成為首要任務時,清理提交,堅持分支策略并編寫一致的提交消息變得很重要。

I’ll start with the list of commonly used commands to make it easier for newbies to understand what is possible with Git, then move into the more advanced functionality and best practices.

我將從常用命令列表開始,以使新手更容易理解Git的功能,然后進入更高級的功能和最佳實踐。

常用命令 (Regularly used commands)

To initialize Git in a repository (repo), you just need to type the following command. If you don’t initialize Git, you cannot run any other Git commands within that repo.

要在存儲庫(倉庫)中初始化Git,只需輸入以下命令。 如果不初始化Git,則無法在該存儲庫中運行任何其他Git命令。

git init

If you’re using GitHub and you’re pushing code to a GitHub repo that’s stored online, you’re using a remote repo. The default name (also known as an alias) for that remote repo is origin. If you’ve copied a project from Github, it already has an origin. You can view that origin with the command git remote -v, which will list the URL of the remote repo.

如果您使用的是GitHub,并且要將代碼推送到在線存儲的GitHub存儲庫中,那么您使用的是遠程存儲庫。 該遠程倉庫的默認名稱(也稱為別名)為origin 。 如果您從Github復制了一個項目,則該項目已經有一個origin 。 您可以使用命令git remote -v查看該來源,該命令將列出遠程倉庫的URL。

If you initialized your own Git repo and want to associate it with a GitHub repo, you’ll have to create one on GitHub, copy the URL provided, and use the command git remote add origin <URL>, with the URL provided by GitHub replacing “<URL>”. From there, you can add, commit, and push to your remote repo.

如果您初始化了自己的Git存儲庫并將其與GitHub存儲庫相關聯,則必須在GitHub上創建一個Git存儲庫,復制提供的URL,然后使用git remote add origin <U RL>命令,以及GitHub替換“ <URL>”。 從那里,您可以添加,提交并推送到您的遠程倉庫。

The last one is used when you need to change the remote repository. Let’s say you copied a repo from someone else and want to change the remote repository from the original owner’s to your own GitHub account. Follow the same process as git remote add origin, except use set-url instead to change the remote repo.

最后一個用于需要更改遠程存儲庫的情況。 假設您從其他人那里復制了一個存儲庫,并且想要將遠程存儲庫從原始所有者的更改為您自己的GitHub帳戶。 遵循與git remote add origin相同的過程,除了使用set-url來更改遠程倉庫。

git remote -vgit remote add origin <url>git remote set-url origin <url>

The most common way to copy a repo is to use git clone, followed by the URL of the repo.

復制存儲庫最常見的方法是使用git clone,然后是存儲庫的URL。

Keep in mind that the remote repository will be linked to the account from which you cloned the repo. So if you cloned a repo that belongs to someone else, you will not be able to push to GitHub until you change the origin using the commands above.

請記住,遠程存儲庫將鏈接到克隆存儲庫的帳戶。 因此,如果您克隆了屬于其他人的存儲庫,那么您將無法將其推送到GitHub,除非您使用上述命令更改了

git clone <url>

You’ll quickly find yourself using branches. If you don’t understand what branches are, there are other tutorials that are much more in-depth, and you should read those before proceeding (here’s one).

您會很快發現自己使用分支機構。 如果您不了解什么是分支,那么還有其他一些教程會更加深入,您應該在繼續之前閱讀這些教程( 這是 )。

The command git branch lists all branches on your local machine. If you want to create a new branch, you can use git branch <name>, with &lt;name> representing the name of the branch, such as “master”.

命令git branch列出了本地計算機上的所有分支。 如果要創建新分支,則可以使用git branch <na me>, 其中& lt; name>代表分支的名稱,例如“ master”。

The git checkout <name> command switches to an existing branch. You can also use the git checkout -b &lt;name> command to create a new branch and immediately switch to it. Most people use this instead of separate branch and checkout commands.

git checkout <na me>命令切換到現有分支。 您還可以使用git checkout -b& lt; name>命令來創建一個新分支,并立即切換到該分支。 大多數人使用此命令而不是單獨的分支和簽出命令。

git branchgit branch <name>git checkout <name>git checkout -b <name>

If you’ve made a bunch of changes to a branch, let’s call it “develop”, and you want to merge that branch back into your master branch, you use the git merge <branch> command. You’ll want to checkout the master branch, then run git merge develop to merge develop into the master branch.

如果您對分支進行了很多更改,我們將其稱為“開發”,并且想要將該分支合并回分支,請使用git merge <bran ch>命令。 你會娃NT以CH eckout主分支中,n運行git合并d evelop合并發展成為主分支。

git merge <branch>

If you’re working with multiple people, you’ll find yourself in a position where a repo was updated on GitHub, but you don’t have the changes locally. If that’s the case, you can use git pull origin <branch> to pull the most recent changes from that remote branch.

如果您與多個人一起工作,您會發現自己在GitHub上更新了一個倉庫的位置,但是本地沒有這些更改。 在這種情況下,可以使用git pull origin <bran ch>從該遠程分支中提取最新更改。

git pull origin <branch>

If you’re curious to see what files have been changed and what’s being tracked, you can use git status. If you want to see how much each file has been changed, you can use git diff to see the number of lines changed in each file.

如果您想知道哪些文件已更改以及正在跟蹤什么,可以使用git status 。 如果要查看每個文件已更改了多少 ,可以使用git diff查看每個文件中更改的行數。

git statusgit diff --stat

高級命令和最佳做法 (Advanced commands and best practices)

Soon you reach a point where you want your commits to look nice and stay consistent. You might also have to fiddle around with your commit history to make your commits easier to comprehend or to revert an accidental breaking change.

很快,您就可以使提交看起來不錯并保持一致。 您可能還必須弄亂自己的提交歷史記錄,以使您的提交更易于理解或還原意外的重大更改。

The git log command lets you see the commit history. You’ll want to use this to see the history of your commits.

git log命令可讓您查看提交歷史記錄。 您將要使用它來查看提交的歷史記錄。

Your commits will come with messages and a hash, which is random series of numbers and letters. An example hash might look like this: c3d882aa1aa4e3d5f18b3890132670fbeac912f7

您的提交將帶有消息和哈希哈希是由數字和字母組成的隨機序列。 示例哈希可能看起來像這樣: c3d882aa1aa4e3d5f18b3890132670fbeac912f7

git log

Let’s say you pushed something that broke your app. Rather than fix it and push something new, you’d rather just go back one commit and try again.

假設您推送了一些破壞您應用程序的內容。 與其修復并推送新內容,不如回退一次提交然后重試。

If you want to go back in time and checkout your app from a previous commit, you can do this directly by using the hash as the branch name. This will detach your app from the current version (because you’re editing a historical record, rather than the current version).

如果您想回到過去并從上一次提交中簽出您的應用程序,則可以直接使用哈希作為分支名稱來執行此操作。 這會將您的應用程序與當前版本分離(因為您正在編輯歷史記錄,而不是當前版本)。

git checkout c3d88eaa1aa4e4d5f

Then, if you make changes from that historical branch and you want to push again, you’d have to do a force push.

然后,如果您從該歷史分支進行了更改并且想要再次推送,則必須進行強制推送。

Caution: Force pushing is dangerous and should only be done if you absolutely must. It will overwrite the history of your app and you will lose whatever came after.

小心:用力推動 是危險的,只有在絕對必要時才應這樣做。 它將覆蓋您的應用程序的歷史記錄,您將失去所有后續內容。

git push -f origin master

Other times it’s just not practical to keep everything in one commit. Perhaps you want to save your progress before trying something potentially risky, or perhaps you made a mistake and want to spare yourself the embarrassment of having an error in your version history. For that, we have git rebase.

在其他時候,將所有內容保持在一次提交中是不切實際的。 也許您想在嘗試可能有風險的操作之前保存進度,或者您犯了一個錯誤,并且想避免在版本歷史記錄中出現錯誤的尷尬。 為此,我們有git rebase

Let’s say you have 4 commits in your local history (not pushed to GitHub) in which you’ve gone back and forth. Your commits look sloppy and indecisive. You can use rebase to combine all of those commits into a single, concise commit.

假設您在本地歷史記錄中有4次提交(未推送到GitHub),在這些提交中來回走了。 您的提交看起來很草率,猶豫不決。 您可以使用rebase將所有這些提交合并為一個簡潔的提交。

git rebase -i HEAD~4

The above command will open up your computer’s default editor (which is Vim unless you’ve set it to something else), with several options for how you can change your commits. It will look something like the code below:

上面的命令將打開計算機的默認編輯器(除非已將Vim設置為其他名稱,否則將為Vim),其中包含用于更改提交的幾種選項。 它看起來像下面的代碼:

pick 130deo9 oldest commit messagepick 4209fei second oldest commit messagepick 4390gne third oldest commit messagepick bmo0dne newest commit message

In order to combine these, we need to change the “pick” option to “fixup” (as the documentation below the code says) to meld the commits and discard the commit messages. Note that in vim, you need to press “a” or “i” to be able to edit the text, and to save and exit, you need to type the escape key followed by “shift + z + z”. Don’t ask me why, it just is.

為了將這些結合起來,我們需要將“ pick”選項更改為“ fixup”(如代碼下面的文檔所述),以合并提交并丟棄提交消息。 請注意,在vim,你需要按“ ”或“ ”才能夠編輯文本,保存并退出,則需要鍵入轉義鍵,然后按“Shift + Z + Z”。 不要問我為什么,就是這樣。

pick 130deo9 oldest commit messagefixup 4209fei second oldest commit messagefixup 4390gne third oldest commit messagefixup bmo0dne newest commit message

This will merge all of your commits into the commit with the message “oldest commit message”.

這會將您所有的提交合并到帶有“最早提交消息”消息的提交中。

The next step is to rename your commit message. This is entirely a matter of opinion, but so long as you follow a consistent pattern, anything you do is fine. I recommend using the commit guidelines put out by Google for Angular.js.

下一步是重命名您的提交消息。 這完全是一個見解,但是只要您遵循一致的模式,您所做的任何事情都可以。 我建議使用Google針對Angular.js提出的提交準則 。

In order to change the commit message, use the amend flag.

為了更改提交消息,請使用amend標志。

git commit --amend

This will also open vim, and the text editing and saving rules are the same as above. To give an example of a good commit message, here’s one following the rules from the guideline:

這也將打開vim,并且文本編輯和保存規則與上述相同。 為了給出良好的提交消息的示例,以下是遵循準則的規則之一:

feat: add stripe checkout button to payments page
- add stripe checkout button- write tests for checkout

One advantage to keeping with the types listed in the guideline is that it makes writing change logs easier. You can also include information in the footer (again, specified in the guideline) that references issues.

與指南中列出的類型保持一致的一個優點是,它使編寫更改日志更加容易。 您還可以在頁腳 (同樣,在指南中指定)中包含引用問題的信息。

Note: you should avoid rebasing and squashing your commits if you are collaborating on a project, and have code pushed to GitHub. If you start changing version history under people’s noses, you could end up making everyone’s lives more difficult with bugs that are difficult to track.

注意 :如果您在一個項目上進行協作,并且代碼已推送到GitHub,則應避免重新提交和壓縮提交。 如果您開始在人們的眼皮底下更改版本歷史記錄,最終可能會因難以跟蹤的錯誤而使每個人的生活更加困難。

There are an almost endless number of possible commands with Git, but these commands are probably the only ones you’ll need to know for your first few years of programming.

Git幾乎有無數種可能的命令,但是這些命令可能是您在編程的頭幾年中唯一需要知道的命令。

Sam Corcos is the lead developer and co-founder of Sightline Maps, the most intuitive platform for 3D printing topographical maps, as well as LearnPhoenix.io, an intermediate-advanced tutorial site for building scalable production apps with Phoenix and React.

Sam Corcos是Sightline Maps (用于3D打印地形圖的最直觀的平臺)以及LearnPhoenix.io (用于使用Phoenix和React構建可擴展的生產應用程序的中級高級教程網站)的首席開發人員和共同創始人。

翻譯自: https://www.freecodecamp.org/news/git-cheat-sheet-and-best-practices-c6ce5321f52/

git 命令git 地址

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

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

相關文章

兩個隊列實現一個棧思路c語言,兩個棧實現隊列功能C語言實現能運行!

#include#includetypedef struct sq{char *ps;int top;int Maxsize;}stack;void initstack(stack *s,int ms){s->ps(char*)malloc(ms*sizeof(char));s->top-1;s->Maxsizems;};void push(stack *s,char val){if(s->tops->Maxsize-1){printf("棧已滿\n"…

基本入門程序編寫格式和注意事項

在安裝好JDK后聯系程序的基本寫法。1、先創建記事本&#xff0c;如果有超級記事本如:notepad、ultraedit、editplus等更好。重命名把記事本后面的后綴名改為.java 但是值得注意的是要看看自己創建的記事本文檔是否是隱藏后綴名的。要是有設置隱藏的就取消隱藏&#xff0c;以免混…

.dll文件存在但是不顯示_一招巧妙解決U盤內文件明明存在,打開U盤而內容卻不顯示的問題...

大家可能都遇到過這種情況&#xff0c;就是說U盤中明明有文件&#xff0c;但是插在電腦上就是什么文件都沒有&#xff0c;一片空白&#xff0c;這樣的問題對于那些對文件很重要且僅保存了1份的人來說是很.kongbu.&#xff0c;因為U盤中的內容都是命根子。給大家介紹絕對有用的解…

《java入門第一季》之面向對象(包概述)

由于eclipse等ide的強大功能&#xff0c;使得建包&#xff0c;導包用一些快捷鍵就能完成。這里對包的概念做稍微的敘述&#xff0c;了解即可&#xff1a; 分包后使得項目更加清晰&#xff0c;提高代碼維護性。 包&#xff1a; A:其實就是文件夾 B:作用 …

Vue 框架-05-動態綁定 css 樣式

Vue 框架-05-動態綁定 css 樣式 今天的小實例是關于 Vue 框架動態綁定 css 樣式&#xff0c;這也是非常常用的一個部分 首先說一下 動態綁定&#xff0c;相對的大家都知道靜態綁定&#xff0c;靜態綁定的話&#xff0c;直接加 class“”就可以了&#xff0c;使用 Vue 呢之前也介…

ember.js_如何設置基本的Ember.js應用

ember.jsby Tracy Lee | ladyleet特雷西李(Tracy Lee)| Ladyleet 如何設置基本的Ember.js應用 (How to set up a Basic Ember.js app) So, you want to test out Ember, eh? This article will walk through building a basic app.所以&#xff0c;您想測試Ember&#xff0c;…

分數轉小數C語言,這是把小數轉換成分數的程序,可是輸入0.6666無限循環

該樓層疑似違規已被系統折疊 隱藏此樓查看此樓#include int main(){double a;scanf("%lf", &a);輸入小數int b, c 0, d 0;double b1 a;do{b1 *10;b (int)b1;printf("%d\n", b);if(b%10!0){c;if(d>0){c d;d 0;}}else{d;}}while(d<5);printf("…

arm處理器的歷史及現狀

1 arm處理器的發展歷史 arm1 arm2 arm3 arm6 arm7 arm9 arm11 arm cortex 2 arm處理器現狀 arm cortex A a即application&#xff0c;即應用處理器&#xff0c;主要用在智能手機、平板電腦和服務器上。 arm cortex M m即mcu&#xff0c;即單片機上的處理器&#xff0c;它的特點…

Linq常用List操作總結,ForEach、分頁、交并集、去重、SelectMany等

1 /*2 以下圍繞Person類實現&#xff0c;Person類只有Name和Age兩個屬性3 一.List<T>排序4 1.1 List<T>提供了很多排序方法&#xff0c;sort(),Orderby(),OrderByDescending().5 */6 7 lstPerson lstPerson.OrderByDescending(x>x.Name).ToList(); //降序8 ls…

bool查詢原理 es_ES系列之原理copy_to用好了這么香

寫在前面Elasticsearch(以下簡稱ES)有個copy_to的功能&#xff0c;之前在一個項目中用到&#xff0c;感覺像是發現了一個神器。這個東西并不是像有些人說的是個語法糖。它用好了不但能提高檢索的效率&#xff0c;還可以簡化查詢語句。基本用法介紹直接上示例。先看看mapping&am…

加密算法—MD5、RSA、DES

最近因為要做一個加密的功能&#xff0c;簡單了解了一下加密算法&#xff0c;現在比較常用的有三個加密算法MD5加密算法、RSA加密算法、DES加密算法。 MD5加密算法 定義&#xff1a;MD5算法是將任意長度的“字節串”變換成一個128bit的大整數&#xff0c;并且它是一個不可逆的字…

隨機加密_隨機藝術和加密圣誕樹

隨機加密When I first learned how to code, one of my first tasks was setting up an SSH key so I could use encryption to securely connect to my friend’s Linux server.當我第一次學習如何編碼時&#xff0c;我的第一個任務是設置SSH密鑰&#xff0c;以便可以使用加密…

用c語言編寫一個2048 游戲,求c語言編寫的2048游戲代碼,盡量功能完善一些

正在編寫中&#xff0c;請稍后&#xff01;追答 : 代碼來了&#xff01;有點急&#xff0c;沒做界面。追答 : 2048_launcher。c&#xff1a;#include#include#includevoid main(){printf("正在啟動中&#xff0c;請稍后&#xff01;");Sleep(1000);system("bin\…

MySQL之數據庫對象查看工具mysqlshow

mysqlshow&#xff1a;數據庫對象查看工具&#xff0c;用來快速查找存在哪些數據庫、數據庫中的表、表中的列或索引。選項&#xff1a;--count 顯示數據庫和表的統計信息-k 顯示指定的表中的索引-i 顯示表的狀態信息不帶任何參數顯示所有數據庫[rootwww mys…

軟件工程分組

電子零售系統 陳仔祥 孟拓 陳庚 汪力 郭澳林 崔祥岑 劉校 肖宇 武清 胡圣陽轉載于:https://www.cnblogs.com/2231c/p/9960751.html

vnr光學識別怎么打開_干貨|指紋鎖的指紋識別模塊的前世今生,智能鎖的指紋識別到底有多智能?...

智能鎖現在也有很多叫法&#xff1a;指紋鎖、電子鎖。可見指紋識別是智能鎖的核心功能了&#xff0c;那我們今天來聊聊智能鎖的指紋識別模塊。指紋識別的歷史指紋識別認證的流程指紋識別技術的種類指紋識別的歷史早在2000多年前我國古代的人就將指紋用于簽訂合同和破案了&#…

使用Kakapo.js進行動態模擬

by zzarcon由zzarcon 使用Kakapo.js進行動態模擬 (Dynamic mocking with Kakapo.js) 3 months after the first commit, Kakapo.js reaches the first release and we are proud to announce that now it is ready to use. Let us introduce you Kakapo.首次提交3個月后&#…

android ble 實現自動連接,Android:自動重新連接BLE設備

經過多次試驗和磨難之后,這就是我最好讓Android自動連接的唯一用戶操作是首先選擇設備(如果使用設置菜單然后首先配對).您必須將配對事件捕獲到BroadcastReceiver中并執行BluetoothDevice.connectGatt()將autoconnect設置為true.然后當設備斷開連接時,調用gatt.connect().更新&…

萊斯 (less)

less中的變量 1、聲明變量&#xff1a;變量名&#xff1a;變量值 使用變量名&#xff1a;變量名 less中的變量類型 ①數字類1 10px ②字符串&#xff1a;無引號字符串red和有引號字符串"haha" ③顏色類red#000000 rgb() …

hackintosh黑蘋果_如何構建用于編碼的Hackintosh

hackintosh黑蘋果by Simon Waters西蒙沃特斯(Simon Waters) 如何構建用于編碼的Hackintosh (How to build a Hackintosh for coding) Let’s talk about Hackintosh-ing — the installation of Mac OS X on PC hardware.我們來談談Hackintosh-ing-在PC硬件上安裝Mac OSX。 I…