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

vue项目示例代码git_您应该了解的5个Git命令以及代码示例相关推荐

  1. 基于git命令的代码统计方法

    基于git命令的代码统计方法 没什么好说的,基于git log命令,使用前提是安装了git ......1.统计所有人代码量 统计所有人代码增删量,拷贝如下命令,直接在git bash等终端,git项 ...

  2. git命令进行代码回滚

    git命令进行代码回滚 1:回滚到你的目标提交记录 2:在你的项目路径下打开git命令面板 git安装路径,安装过的无需安装:下载地址 使用命令:git reset –hard [commit] 该命 ...

  3. git命令统计代码量

    git命令统计代码量 命令行 git log --since=2020-07-01 --until=2020-07-31 --pretty=tformat: --numstat | awk '{ ad ...

  4. Vue项目运行报错,‘webpack-dev-server‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。

    刚导入的Vue项目报 'webpack-dev-server' 不是内部或外部命令,也不是可运行的程序 或批处理文件.错误 在项目的控制台输入以下命令: npm install webpack-dev ...

  5. git bash here创建项目无法选择m_你应该知道的10个Git命令

    作者 | Jeff Hale 来源 | Towards Data Science 编辑 | 代码医生团队 在本文中,将讨论作为开发人员,数据科学家或产品经理应该了解的各种Git命令.将看看使用Git检 ...

  6. linux github代码仓库,centos7上使用git命令把代码放到github上

    git仓库相关说明: 有关仓库这里着重说明下: 一种情况是本地没有仓库,而在github上有自己的仓库名称,需要从github上clone仓库(项目)到本地,这样就会在执行git clone命令的当前 ...

  7. .net 本地文件管理 代码_Gitee 在线解决代码冲突上线,解决冲突不再需要 Git 命令...

    IT服务圈儿 有温度.有态度的IT自媒体平台 来源: OSCHINA 社区 [http://www.oschina.net] 作者:码云Gitee 许多开发者在使用 Git 的时候会遇到代码冲突的情况 ...

  8. Git命令(用git命令将代码下载到本地)

    1.下载自己电脑对应的git版本 并安装 下载地址:1https://git-scm.com/ 安装成功后,打开 git bash命令行,如图: 2.使用git命令 1) git --version ...

  9. Git 命令提交代码

    0. 拉取某项目代码:先cd到某个目录下. git  clone xxxxx某项目git地址. cd 项目名 1. git放弃本次某文件的修改 git status   //查看当前分支更新内容. g ...

最新文章

  1. 算法练习——ACM_1001_Exponentiation
  2. MySQL的高级运用_MYSQL之SQL高级运用(帮助你高效率编程)
  3. Tomcat类加载器为何违背双亲委派模型
  4. 打印杨辉三角(数组练习)
  5. Ta 在假笑么?这个识别算法可以鉴定
  6. Socket,CAsyncSocket,CSocket介绍
  7. 【BZOJ1951】古代猪文(CRT,卢卡斯定理)
  8. linux部署was找不到8879端口,WAS8.0与IHS集群安装与配置指导手册
  9. 学习笔记五:xss.tv通关笔记
  10. JAVA-JDK环境变量配置
  11. html文件转为其他格式文件格式,HTML文件转Word文件格式
  12. 机器学习之多项式拟合
  13. 巨头发力,社区电子商务发展加速
  14. uni-app +vue+微信小程序 发布线上
  15. 实用算法 002: SAM 上的根号暴力
  16. 阐述游戏AI设计的两个禁忌及解决方法
  17. 树或者二叉树的度怎么算??
  18. 梯度提升树(GBDT)算法超详细版本
  19. MySQL常见高可用方案
  20. ug如何复制面_UG复制面,移动面,删除面,镜像面,替换面,阵列面命令用法与作用...

热门文章

  1. Spring主要用到两种设计模式
  2. 后端视角下的前端框架之Vue.js初探
  3. Problem B: 字符类的封装
  4. [转]Java7中的ForkJoin并发框架初探(上)——需求背景和设计原理
  5. 数据:ContentResolver类
  6. ldconfig deferred processing now taking place
  7. UNIX网络编程——套接字选项(SO_RCVBUF和SO_SNDBUF)
  8. [转]项目失败的经验
  9. 1.1 算法编译与调试
  10. 阿里云对数据可靠性保障的一些思考