vue項目示例代碼git_您應該了解的5個Git命令以及代碼示例

vue項目示例代碼git

I've used Git for some years now, and I still find myself googling how to do some basic tasks. So this article is my attempt to learn how to do some of these things by writing about them. And even if I still forget, at least I'll have a reference where I can easily find these commands – and you will, too.

我已經使用Git幾年了,但我仍然發現自己在搜尋如何執行一些基本任務。 因此,本文是我嘗試通過撰寫文章來學習如何做這些事情的嘗試。 即使我仍然忘記了,至少我會有一個參考,在這里我可以輕松找到這些命令,您也將找到。

Before we move on to learn these things, something a colleague of mine once said has stuck with me. He told me that everything is possible with Git and that nothing is lost in Git.

在我們繼續學習這些東西之前,我的一位同事曾經說過一句話。 他告訴我,Git可以實現一切,而Git不會丟失任何東西。

I don't know if the former part of his statement is entirely true but I keep it in mind every time I try to do something with Git. I believe that I'm going to find a command that will help me do what I need to do. I just have to google with the right words. If you are new to Git, I want you to believe that, too.

我不知道他聲明的前一部分是否完全正確,但是每次我嘗試對Git進行操作時,我都會牢記這一點。 我相信我將找到一條命令,該命令將幫助我完成需要做的事情。 我只需要用正確的詞來谷歌搜索。 如果您是Git的新手,我也希望您也相信這一點。

In this article, we'll learn how to do the following:

在本文中,我們將學習如何執行以下操作:

  1. Add remote repositories

    添加遠程存儲庫
  2. Change remote repositories

    更改遠程存儲庫
  3. Delete a branch

    刪除分支
  4. Merge a file from one branch to another

    將文件從一個分支合并到另一個分支
  5. Undo a commit locally and remotely

    本地和遠程撤消提交

Though this article is intended for people with a basic knowledge of Git, I'll do my best to explain terms as much as possible.

盡管本文是為具有Git基礎知識的人準備的,但我會盡力解釋盡可能多的術語。

1.添加遠程存儲庫 (1. Add Remote Repositories)

Remote repositories are versions of your projects that are stored on the internet or elsewhere. Adding a remote repository is a way of telling Git where your code is stored.

遠程存儲庫是存儲在Internet或其他地方的項目的版本。 添加遠程存儲庫是一種告訴Git代碼存儲在哪里的方法。

We can do this using the URL of the repository. This could be the URL of your repository, another user's fork, or even a completely different server.

我們可以使用存儲庫的URL進行此操作。 這可能是您的存儲庫的URL,另一個用戶的fork甚至是完全不同的服務器。

When you clone a repository, Git implicitly adds that repository as the origin remote for you. To add a new Git repository, you use this command:

克隆存儲庫時,Git隱式將該存儲庫添加為您的origin遠程站點。 要添加新的Git存儲庫,請使用以下命令:

git remote add <shortname> <url>

where shortname is a unique remote name and url is the url of the repository you want to add.

其中shortname是唯一的遠程名稱,而url是要添加的存儲庫的url。

For example, if I want to add a repository with the shortname upstream, I can do this:

例如,如果我想添加一個短名稱為upstream的存儲庫,則可以這樣做:

git remote add upstream https://github.com/sarahchima/personal-website.git

Remember that your shortname can be anything, it just has to be unique, that is different from what the names of the remote repositories you already have. It should also be something you can easily remember for your sanity.

請記住,您的shortname可以是任何東西,它必須唯一,這與您已有的遠程存儲庫的名稱不同。 您也應該為自己的理智而輕易記住它。

To view the list of remote URLs you have added, run the following command:

要查看已添加的遠程URL列表,請運行以下命令:

git remote -v

You'll see a list of the remote names and the URLs you have added.

您將看到一個遠程名稱和添加的URL的列表。

But what if you want to change these remote URLs? Let's move to the next Git command.

但是,如果您想更改這些遠程URL怎么辦? 讓我們轉到下一個Git命令。

2.更改遠程存儲庫 (2. Change remote repositories)

There are several reasons why you may want to change a remote URL. For example, I recently had to move from using https URLs to SSH URLs for a project I worked on.

您可能要更改遠程URL的原因有多種。 例如,最近我不得不從使用https URL轉到我從事的項目的SSH URL。

To do this, you use the following command:

為此,請使用以下命令:

git remote set-url <an-existing-remote-name> <url>

For this command to work, the remote name has to be an existing remote name. That means it won't work if you've not added that remote name before.

為了使此命令起作用,遠程名稱必須是現有的遠程名稱。 這意味著如果您之前未添加該遠程名稱,它將無法正常工作。

Using the example above, if I want to change the remote URL, I'll do this:

使用上面的示例,如果要更改遠程URL,將執行以下操作:

git remote set-url upstream git@github.com:sarahchima/personal-website.git

Remember to run git remote -v to verify that your change worked.

請記住運行git remote -v來驗證您的更改是否有效。

Enough about remote repositories. Let's move on to something different.

足夠用于遠程存儲庫。 讓我們繼續一些不同的事情。

3.在本地和遠程刪除分支 (3. Delete a branch both locally and remotely)

A branch is a version of the repository that is different from the main working project. You may want to read up on Git branches and how to add a branch if you are not familiar with that process.

分支是存儲庫的版本,與主要工作項目不同。 如果您不熟悉該過程,則可能需要閱讀有關Git分支以及如何添加分支的信息。

如何刪除本地分支 (How to delete a local branch)

To delete a branch locally, make sure you are not on the branch you want to delete. So you have to checkout to a different branch and use the following command:

要在本地刪除分支,請確保您不在要刪除的分支上。 因此,您必須簽出到其他分支并使用以下命令:

git branch -d <name-of-branch>

So if I want to delete a branch named fix/homepage-changes, I'll do the following:

因此,如果要刪除一個名為fix/homepage-changes的分支,將執行以下操作:

git branch -d fix/homepage-changes

You can run git branch on your terminal to confirm that the branch has been successfully removed.

您可以在終端上運行git branch ,以確認該分支已成功刪除。

Sometimes you may have to delete a branch you've already pushed to a remote repository. How can you do this?

有時,您可能必須刪除已經推送到遠程存儲庫的分支。 你該怎么做?

如何刪除遠程分支 (How to delete a remote branch)

To delete a branch remotely, you use the following command:

要遠程刪除分支,請使用以下命令:

git push <remote-name> --delete <name-of-branch>

where remote-name is the name of the remote repository you want to delete the branch from.

其中remote-name是要從中刪除分支的遠程存儲庫的名稱。

If I want to delete the branch fix/homepage-changes from origin, I'll do this:

如果我想從origin刪除分支fix/homepage-changes ,我將執行以下操作:

git push origin --delete fix/homepage-changes

The branch will be deleted remotely now.

現在該分支將被遠程刪除。

4.將文件從一個分支合并到另一個分支 (4. Merge a file from one branch to another)

Sometimes, you may want to merge the content of a specific file in one branch into another. For example, you want to merge the content of a file index.html in the master branch of a project into the development branch. How can you do that?

有時,您可能希望將一個分支中特定文件的內容合并到另一個分支中。 例如,您要將項目的master分支中的index.html文件的內容合并到development分支中。 你該怎么做?

First, checkout to the right branch (the branch you want to merge the file) if you've not already done so. In our case, it's the development branch.

首先,簽出到右分支(要合并文件的分支)(如果尚未這樣做)。 在我們的案例中,它是development部門。

git checkout development

Then merge the file using the checkout --patch command.

然后使用checkout --patch命令合并文件。

git checkout --patch master index.html

If you want to completely overwrite the index.html file on the development branch with the one on the master branch, you leave out the --patch flag.

如果要用master分支上的文件完全覆蓋development分支上的index.html文件,則可以--patch標志。

git checkout master index.html

Also, leave out the --patch flag if the index.html file does not exist on the development branch.

另外,如果在development分支上不存在index.html文件,則--patch標志。

5.撤消提交 (5. Undo a commit)

There are times when you've committed your changes incorrectly and you want to undo this commit. Sometimes, you may have even pushed the changes to a remote branch. How do you undo or delete this commit? Let's start with undoing a local commit.

有時候,您錯誤地提交了更改,而您想撤消此提交。 有時,您甚至可能將更改推送到遠程分支。 您如何撤消或刪除此提交? 讓我們從撤消本地提交開始。

如何撤消本地提交 (How to undo a local commit)

One way you can undo a commit locally is by using git reset. For example, if you want to undo the last commit made, you can run this command:

您可以在本地撤消提交的一種方法是使用git reset 。 例如,如果要撤消上一次提交的操作,可以運行以下命令:

git reset --soft HEAD~1

The --soft flag preserves the changes you've made to the files you committed, only the commit is reverted. However, if you don't want to keep the changes made to the files, you can use the --hard flag instead like this:

--soft標志保留您對提交的文件所做的更改,僅還原提交。 但是,如果您不想保留對文件所做的更改,則可以使用--hard標志,如下所示:

git reset --hard HEAD~1

Note that you should use the --hard flag only when you are sure that you don't need the changes.

請注意,僅當確定不需要更改時,才應使用--hard標志。

Also, note that HEAD~1 points to the last commit. If you want to undo a commit before that, you can use git reflog to get a log of all previous commits. Then use the git reset command with the commit hash (the number you get at the beginning of each line of history). For example, if my commit hash is 9157b6910, I'll do this

另外,請注意HEAD~1指向最后一次提交。 如果您想在此之前撤消提交,則可以使用git reflog獲取所有先前提交的日志。 然后將git reset命令與提交哈希(在歷史記錄的每一行開頭獲得的數字)一起使用。 例如,如果我的提交哈希為9157b6910 ,我將這樣做

git reset --soft 9157b6910

如何撤消遠程提交 (How to undo a remote commit)

There are times you want to undo a commit you have pushed to a remote repository. You can use git revert to undo it locally and push this change to the remote branch.

有時您想撤消已推送到遠程存儲庫的提交。 您可以使用git revert在本地撤消它,并將此更改推送到遠程分支。

First, get the commit hash using git reflog.

首先,使用git reflog獲取提交哈希。

git reflog

Then revert it. Assuming my commit hash is 9157b6910, I'll do the following:

然后還原它。 假設我的提交哈希為9157b6910,我將執行以下操作:

git revert 9157b6910

Finally, push this change to the remote branch.

最后,將此更改推送到遠程分支。

摘要 (Summary)

In this article, we discussed commands to do the following in Git:

在本文中,我們討論了在Git中執行以下操作的命令:

  1. Add Remote Repositories

    添加遠程存儲庫
  2. Change remote repositories

    更改遠程存儲庫
  3. Delete a branch

    刪除分支
  4. Merge a file from one branch to another

    將文件從一個分支合并到另一個分支
  5. Undo a commit locally and remotely

    本地和遠程撤消提交

Maybe someday, I'll write about more things you can do with Git.

也許有一天,我會寫更多關于Git可以做的事情。

I hope you enjoyed the article. Thanks for reading.

希望您喜歡這篇文章。 謝謝閱讀。

Want to get notified when I publish a new article? Click here.

想在我發表新文章時得到通知嗎? 請點擊這里 。

翻譯自: https://www.freecodecamp.org/news/5-git-commands-you-should-know-with-code-examples/

vue項目示例代碼git

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

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

相關文章

413. 等差數列劃分

413. 等差數列劃分 如果一個數列 至少有三個元素 &#xff0c;并且任意兩個相鄰元素之差相同&#xff0c;則稱該數列為等差數列。 例如&#xff0c;[1,3,5,7,9]、[7,7,7,7] 和 [3,-1,-5,-9] 都是等差數列。 給你一個整數數組 nums &#xff0c;返回數組 nums 中所有為等差數組…

山羊與汽車游戲的實驗算法

實驗1&#xff1a; function shuffle(target) {var j, x, i target.length;for (; i > 0; j parseInt(Math.random() * i), x target[--i], target[i] target[j], target[j] x) {}return target }function removeAt(target, index) {return !!target.splice(index, 1).…

selenium模塊

selenium模塊 閱讀目錄 一 介紹二 安裝三 基本使用四 選擇器五 等待元素被加載六 元素交互操作七 其他八 項目練習一 介紹 selenium最初是一個自動化測試工具,而爬蟲中使用它主要是為了解決requests無法直接執行JavaScript代碼的問題selenium本質是通過驅動瀏覽器&#xff0c;完…

關閉iphone來電mac_如何在Mac和iPhone上關閉通用剪貼板切換(以及為什么要禁用此功能)

關閉iphone來電macIm about to tell you something that will shock you, and probably make you very angry. I hope you wont hate me for it. Here goes.我正要告訴您一些令您震驚的事情&#xff0c;并可能使您非常生氣。 我希望你不會為此而恨我。 開始。 If you are an i…

關于tomcat Post 數據參數的問題

2019獨角獸企業重金招聘Python工程師標準>>> POST請求本身并未限制傳入參數大小&#xff0c;是tomcat 容器設置了接收參數大小的限制。修改server.xml <Connector port"8080" protocol"HTTP/1.1" connectionTimeout"2000" red…

iOS:通信錄(完成)(18-01-18更)

1、讀取通信錄 1&#xff09;、9.0以前&#xff1a;AddressBook 2&#xff09;、9.0以后&#xff1a;Contacts 2、調用通信錄UI&#xff08;不弄&#xff09; 1&#xff09;、9.0以前&#xff1a;AddressBookUI 2&#xff09;、9.0以后&#xff1a;ContactsUI 3、參考 0、寫在前…

如何在React Native和Firebase中設置Google登錄

Google sign-in is a great login feature to offer to your apps users. It makes it easier for them to create an account and sign in. Google登錄是一項出色的登錄功能&#xff0c;可為您的應用程序用戶提供。 這使他們更容易創建帳戶并登錄。 And whats even better, F…

設計模式-發布訂閱模式

這段時間在看vue的雙向綁定原理&#xff0c;知道了vue的核心三大件&#xff1a;Observer, Complie, Watcher。 Observer用于監聽屬性的變化&#xff0c;如有變動就通知 Watcher。 Compile負責解析元素節點的指令&#xff0c;如v-if&#xff0c;v-bind之類, 進行數據和回調函數的…

杜教篩--51nod1239 歐拉函數之和

求$\sum_{i1}^{n}\varphi (i)$&#xff0c;$n\leqslant 1e10$。 這里先把杜教篩的一般套路貼一下&#xff1a; 要求$S(n)\sum_{i1}^{n}f(i)$&#xff0c;而現在有一數論函數$g(i)$&#xff0c;$g(i)$的前綴和很無腦&#xff0c;且$f$和$g$的狄利克雷卷積的前綴和很無腦&#xf…

【Android Studio安裝部署系列】目錄

概述 從剛開始使用Android Studio到現在&#xff0c;下面所有目錄下的操作&#xff0c;當時習慣性的把每一個整理成一個文檔&#xff08;其實就是簡單文字描述截圖&#xff09;&#xff1b;有些地方當時是一知半解&#xff0c;現在會稍微明白一些。正好趕上現在有時間。所以就想…

修改npm全局安裝模式的路徑

修改npm全局安裝模式的路徑 在正式寫此文章之前&#xff0c;我得說一點血淚史。 剛學nodeJS不久&#xff0c;很納悶為什么全局安裝的模塊在 node安裝目錄/node_modules‘ 中沒找到&#xff01;后來仔細看了下安裝成功后的信息&#xff0c;才發現原來是自動安裝在C盤了&#xff…

javascript創建類_如何使用JavaScript創建吹氣效果

javascript創建類Have you ever wondered how you can create a realistic air blowing effect with JavaScript? Like the one shown on the evening TV shows, where multiple balls are being mixed up in a sphere-like object by leveraging air pressure? If you want …

Bootstrap 4:如何使頂部固定的Navbar保持在容器中而不拉伸?

There are many ways to make a fixed navbar stay inside a parents div container. Well go over the most straightforward one here.有很多方法可以使固定的導航欄停留在父級的div容器中。 我們將在這里介紹最簡單的方法。 Imagine you have the following code, modified…

基于SpringBoot+Mybatis+Thymeleaf商品信息管理系統

github地址&#xff1a;github.com/zaiyunduan1…,如果對你有幫助&#xff0c;歡迎Star 主要用到的技術&#xff1a; 使用maven進行項目構建使用SpringbootMybatis搭建整個系統使用Thymeleaf模板技術實現頁面靜態化使用框架Bootstrap、JQuery開發前端界面使用MySQL和MongoDB分別…

在Mac上為自己手動編譯安裝一套PHP7的開發環境

首先你得去官網下載php7 beta1的版本 這里由于我是在mac上安裝&#xff0c;所以就去下載linux相關的版本&#xff0c;地址也直接附上了php7 beta1windows版的官方也有發布詳情猛戳&#xff1a;這里 解壓安裝包&#xff0c;進入源代碼目錄 tar -zxvf php-7.0.0beta1.tar.gz cd p…

卡特蘭數 HDU2067 HDU4165 HDU1134

題目鏈接&#xff1a;https://vjudge.net/problem/HDU-2067 小兔的棋盤 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11800 Accepted Submission(s): 5952 Problem Description小兔的叔叔從外面旅游回來給她…

Python的用途是什么? Python編程語言有10多種編碼用途。

&#x1f44b;歡迎 (&#x1f44b; Welcome) Hi! Please take a moment to think about this question: 嗨&#xff01; 請花一點時間考慮這個問題&#xff1a; How is Python applied in real-world scenarios? Python如何在實際場景中應用&#xff1f; If you are learnin…

Publish/Subscribe

Publish/Subscribe 我們將會投遞一個消息給多個消費者&#xff0c;這種模式被稱為“publish/subscribe” 通俗的講&#xff0c;前面的是點對點隊列模型&#xff0c;現在講的是發布訂閱模型。 Exchanges producer&#xff1a;一個發送消息的用戶應用程序 queue&#xff1a;一個存…

[轉]在ROS下使用zeroconf配置多機通信

原文地址&#xff1a;http://www.corvin.cn/635.html&#xff0c;轉載主要方便隨時查閱&#xff0c;如有版權要求&#xff0c;請及時聯系。 0x00 為何需要配置ROS多機通信 眾所周知ROS是分布式系統&#xff0c;因此可以將機器人需要處理的復雜、計算量大的任務分解在多臺機器上…

python中斐波那契數列_斐波那契數列–在Python,JavaScript,C ++,Java和Swift中進行了解釋...

python中斐波那契數列by Pau Pavn通過保羅帕文(PauPavn) The Fibonacci sequence is, by definition, the integer sequence in which every number after the first two is the sum of the two preceding numbers. To simplify:根據定義&#xff0c;斐波那契數列是整數序列&a…