git 代理 git_五分钟解释Git的要点

git 代理 git

by James Okunlade

詹姆斯·奥昆拉德(James Okunlade)

五分钟解释Git的要点 (The essentials of Git explained in five minutes)

As you learn to become a software developer, you’ll realize that most work is done in teams. And when you’re on a team, you’ll need a version control system to manage changes to your code base that come from different developers.

当您学习成为一名软件开发人员时,您会意识到大多数工作都是在团队中完成的。 在团队中时,您将需要一个版本控制系统来管理来自不同开发人员的代码库更改。

Git is one of the most popular version control systems. Yet, new developers can easily get overwhelmed when using it - I know I did. In fact, I avoided it for years.

Git是最流行的版本控制系统之一。 但是,新开发人员在使用它时很容易不知所措-我知道我做到了。 实际上,我避免了很多年。

If you’re a seasoned developer or don’t tremble at the mention of Git, feel free to skip to the next post. However, if you’re new to Git or not confident using it, take a few minutes to learn these basic - yet powerful - Git tips.

如果您是一位经验丰富的开发人员,或者不因提及Git而发抖,请随时跳到下一篇文章。 但是,如果您是Git的新手或不确定使用它,请花几分钟来学习这些基本但功能强大的Git技巧。

Here’s what we’ll cover:

这是我们要介绍的内容:

  1. Git clone

    Git克隆
  2. Git checkout

    Git结帐
  3. Git pull

    git拉
  4. Git add and commit

    Git添加并提交
  5. Git stash and merge

    Git隐藏并合并
  6. Git push

    git推

Git克隆 (Git clone)

Always clone new repositories you work on, which means downloading a copy of the repository files to your local computer. While there are many ways of cloning a repository, I will explain how to do it with the command line.

始终克隆您正在使用的新存储库,这意味着将存储库文件的副本下载到本地计算机。 尽管有很多克隆存储库的方法,但我将解释如何使用命令行来完成。

For example, if you want to clone the above repository, first copy the clone link above. Then, open your terminal, and cd to the location on your local computer where you want to put these files. Type git clone then paste the link as shown below if you want to clone the master branch.

例如,如果要克隆上述存储库,请首先复制上面的克隆链接。 然后,打开您的终端,并cd到您要在其中放置这些文件的本地计算机上的位置。 如果要克隆master分支,请键入git clone,然后粘贴如下所示的链接。

git clone https://github.com/JamesOkunlade/old-apple.git

git clone https://github.com/JamesOkunlade/old-apple.git

If you want to clone a particular branch of this repository, you’d want to do something like this:

如果要克隆此存储库的特定分支,则需要执行以下操作:

git clone https://github.com/JamesOkunlade/old-apple.git -b branch-name

git clone https://github.com/JamesOkunlade/old-apple.git -b branch-name

Git结帐 (Git checkout)

It’s a best practice to create different branches for different features instead of working on the master branch directly. When all features have been deemed to pass certain tests and requirements, then you can merge them into the master branch.

最佳做法是为不同的功能创建不同的分支,而不是直接在master分支上工作。 当所有功能都被认为通过了某些测试和要求后,您可以将它们合并到master分支中。

At different times, you will have to checkout to the particular repository branch you want to work on, and you can do this with the following command.

在不同的时间,您将不得不签出要处理的特定存储库分支,您可以使用以下命令来执行此操作。

If the branch had already been created:

如果分支已经创建:

git checkout branch-name

git checkout branch-name

And if you’re just creating the new feature branch:

如果您只是在创建新的功能分支,请执行以下操作:

git checkout -b branch-name

git checkout -b branch-name

git拉 (Git pull)

Your team or pair programming buddy will change different branches of a repository, and you should always pull these new changes before you start writing code. On your terminal, checkout to the branch you’ll be working on, and run the git pull command. The recent changes will be pulled to your local repository.

您的团队或结对编程的伙伴将更改存储库的不同分支,在开始编写代码之前,应始终提取这些新更改。 在终端上,签出要处理的分支,然后运行git pull命令。 最近的更改将被拉到您的本地存储库。

Git添加并提交 (Git add and commit)

The add and commit Git commands are almost always used together. Think of them as capture and save. You can’t save a thing if you don’t capture it first. Hence, the add command should always precede the commit command. While you use the add command to point at the particular file you want to capture in its current state, you use the commit to save a copy of what you captured.

add和commit Git命令几乎总是一起使用。 将它们视为捕获和保存。 如果不先捕获,就无法保存。 因此,add命令应始终在commit命令之前。 当您使用add命令指向要在其当前状态下捕获的特定文件时,您可以使用提交保存捕获内容的副本。

To capture all the files (except those excluded by Git ignore), you will use git add . and to capture the current state of a particular file, say index.html, you will have to type git add index.html

要捕获所有文件(Git忽略排除的文件除外),您将使用git add . 并捕获特定文件(例如index.html)的当前状态,则必须输入git add index.html

After taking the snapshots, you will then have to commit and save your snapshots to your local repository using the following:

拍摄快照之后,您将必须使用以下命令来提交快照并将其保存到本地存储库:

git commit -m ‘commit message’

git commit -m 'commit message'

The commit message should explain the peculiarity of the snapshot you’re saving. For example:

提交消息应说明您要保存的快照的特殊性。 例如:

git add index.html

git add index.html

git commit -m ‘the form feature button created’

git commit -m 'the form feature button created'

You can do the two together with the && operator as shown below;

您可以与&&运算符一起使用二者,如下所示;

git add index.html && git commit -m ‘footer html structure created’

git add index.html && git commit -m 'footer html structure created'

Git隐藏并合并 (Git stash and merge)

Simply doing git stash will stash whatever edit you have made to the branch but do not want to commit. That means when waiting on another developer to commit and push their copy of the code, you can experiment with some things in this same branch. Git encourages it. Whenever you’re ready to pull new changes to your local repository, but do not want to merge your own edits to it, you then have to stash your own edits. Git stash will keep the copy somewhere else for you and it’s accessible by doing Git stash list.

简单地执行git stash将隐藏您对分支所做的任何编辑,但不想提交。 这意味着当等待另一个开发人员提交并推送其代码副本时,您可以在同一分支中尝试一些操作。 Git鼓励它。 每当您准备将新的更改拉到本地存储库,但又不想将自己的编辑合并到本地存储库时,则必须保存自己的编辑。 Git藏匿处会将副本保存在其他地方,您可以通过执行Git藏匿处列表进行访问。

The git merge a command that merges two different snapshots together. It can be merging different snapshots of the same branch by different developers or merging different snapshots of different branches together.

git merge一个将两个不同快照合并在一起的命令。 它可以由不同的开发人员合并同一分支的不同快照,也可以将不同分支的不同快照合并在一起。

When you’ve checked out to the master branch, git merge development will merge the development branch to your master branch and vice versa.

当您签出到master分支后,git merge development将把development分支合并到您的master分支,反之亦然。

git推 (Git push)

Just like saving your snapshots to a Google Photos album for whomever you share the album with, think of git push as sending your local repository to the remote repository for others to access.

就像将快照保存到与他人共享相册的Google Photos相册一样,将git push视为将本地存储库发送到远程存储库,以供其他人访问。

git push -u origin branch-name

git push -u origin branch-name

While there are other Git commands available for use, it’s interesting what you can achieve by mastering the few that I’ve covered above.

尽管还有其他可用的Git命令,但有趣的是,您可以掌握上面已经介绍的几个命令来实现。

Feel free to reach out and ask me any questions on Twitter

随时联系并在Twitter上问我任何问题

James Okunlade (@JamesOkunlade) | TwitterThe latest Tweets from James Okunlade (@JamesOkunlade). Full-stack SWE | JavaScript/React/Redux | Ruby/Ruby on Rails |…twitter.com

詹姆斯·奥昆拉德(@JamesOkunlade)| Twitter 来自James Okunlade(@JamesOkunlade)的最新推文。 全栈SWE | JavaScript / React / Redux | Ruby / Ruby on Rails |… twitter.com

def JamesOkunlade (beginnerDeveloper)
unless you have a coding buddy OR you’re making a lot of money
doing it
puts “Coding is not fun!”
end
end

I’m from Nigeria and I pair program every day with my coding buddy from Bangladesh and other devs from Serbia, Kosovo, and Ukraine. They’ve all helped my use of Git.

我来自尼日利亚,每天与孟加拉的编码伙伴以及来自塞尔维亚,科索沃和乌克兰的其他开发人员配对程序。 他们都帮助了我使用Git。

As a student, I do remote pair programming for at least 40 hours every week. Learning programming as a beginner can be very tedious and hence, reduces the productivity and hardens the learning curve. With a right coding partner, however, and under a proper structure, you’d be surprised at how interesting learning could be.

作为一名学生,我每周至少进行40个小时的远程配对编程。 初学者学习编程可能非常繁琐,因此会降低生产率并加深学习难度。 但是,如果选择了合适的编码合作伙伴,并且结构正确,您会惊讶于学习会变得多么有趣。

James Okunlade - Software Developer - Filmdrive | LinkedInView James Okunlade's profile on LinkedIn, the world's largest professional community. James has 2 jobs listed on their…www.linkedin.com

James Okunlade-Filmdrive软件开发人员| LinkedIn 查看詹姆斯Okunlade对LinkedIn,世界上最大的专业的社区形象。 詹姆斯在他们的网站列出了2个工作 。www.linkedin.com

翻译自: https://www.freecodecamp.org/news/the-essentials-of-git-explained-in-five-minutes-d554019eded9/

git 代理 git

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值