github 和git_关于git和github的事情,您需要以开发人员的身份知道

github 和git

Hey there, in this blog we are going to learn about Git and Github. As a developer, you might have come across the terms Git and Github but do you understand why do you need or why you are using these? Let’s dig a little deeper to understand these terms.

嘿,在这个博客中,我们将学习Git和Github。 作为开发人员,您可能遇到过Git和Github这两个词,但是您了解为什么需要或为什么要使用它们吗? 让我们更深入地了解这些术语。

什么是Git? (What is Git?)

Git is a free and open-source distributed version control system. It was created by Linus Torvalds in 2005. You can find Git to download at git-scm.com and they also have great resources for documentation.

Git是一个免费的开源分布式版本控制系统。 它由Linus Torvalds在2005年创建。 您可以在git-scm.com上找到要下载的Git,并且它们还有大量的文档资源。

Image for post
Distributed Version Control System 分布式版本控制系统

什么是Github? (What is Github?)

Github is a cloud-based hosting service for Git repositories. It is a tool build on the top of Git. In simple terms, it provides a graphical interface that interacts with Git repositories. It makes it easier for the individual and team to use Git for version control and provide collaboration features such as task management, bug tracking and feature request for every project. You can use Github through a web portal or desktop GUI or Git shell.

Github是用于Git 存储库的基于云的托管服务 。 它是在Git之上构建的工具。 简单来说,它提供了一个与Git存储库交互的图形界面。 它使个人和团队更容易使用Git进行版本控制,并为每个项目提供协作功能,例如任务管理,错误跟踪和功能请求。 您可以通过Web门户桌面GUIGit Shell使用Github。

Other hosting services for Git repository also exist: GitLab, BitBucket. But for this blog we will look at Github only.

还存在用于Git存储库的其他托管服务:GitLab,BitBucket。 但是对于这个博客,我们将仅关注Github。

为什么需要Git和Github? (Why do you need Git and Github?)

  • Easy Collaboration — let multiple developers work on a project where everyone can upload, edit and manage the source code. And can also work in parallel (with help of Branching and Merging) so that there are no code conflicts between them and all developers can work without losing or affecting each other’s work!.

    轻松协作 -让多个开发人员在一个项目上工作,每个人都可以上载,编辑和管理源代码。 并且还可以并行工作(在“ 分支和合并”的帮助下),因此它们之间没有代码冲突,并且所有开发人员都可以工作而不会丢失或影响彼此的工作!

  • Version Tracking — helps you or team to track and manage changes made in the source code. So you can keep the record of what you or your team members have been doing and you can also revert to any specific version if needed.

    版本跟踪-帮助您或团队跟踪和管理源代码中所做的更改。 因此,您可以记录您或您的团队成员的工作记录,还可以根据需要恢复为任何特定版本。

  • Branching and Merging — Let’s say you need to work on a new feature for a website. You create a branch so that you won’t affect the main source code. While working on this new feature you get a request to fix an issue on a live website that too before completing this new feature. You create a new branch from the main branch and finish your work and merge this fix branch in the main branch and continue working on your new feature branch and can easily merge this new feature branch in the main branch without worrying about the changes you make in the fix branch.

    分支和合并 -假设您需要为网站开发一项新功能。 您创建一个分支,以免影响主要的源代码。 在使用此新功能时,您会收到在现场网站上解决问题的请求,该问题也要在完成此新功能之前进行。 您可以从主分支中创建一个新分支,然后完成工作并在主分支中合并此修订分支,然后继续使用新功能分支,并且可以轻松地在主分支中合并此新功能分支,而不必担心在其中所做的更改修复分支。

    But without Git and Github, it will be very difficult to maintain different copies(main copy, feature copy and fix copy) of your source code.

    但是如果没有Git和Github,维护源代码的不同副本(主副本,功能副本和修订副本)将非常困难。

Before we look at why do you need Git and Github, let’s look at some important Git and GitHub terms:

在查看为什么需要Git和Github之前,让我们先看一些重要的Git和GitHub术语:

Image for post
Distributed version control
分布式版本控制

Distributed Version Control SystemThis type of version control allows the clone of the complete codebase (repository) including its full history on every developer’s system. If any time server(main repository) dies, any of the developer’s repository can be copied on to the server which helps restore the server. And it helps the software team or individual in managing and keep the track of changes made in the source code in a special kind of database. It takes the snapshots of every revision of your source code, which you can access to compare or restore them as needed. In another word, it gives you the power to review or even restore the earlier versions of your source code.

分布式版本控制系统这种类型的版本控制允许克隆完整的代码库( 存储库 ),包括每个开发人员系统上的完整历史记录。 如果服务器( 主存储库)死亡,则可以将任何开发人员的存储库复制到服务器上,这有助于恢复服务器。 它可以帮助软件团队或个人在特殊的数据库中管理和跟踪源代码中所做的更改。 它获取源代码的每个修订版本的快照,您可以访问这些快照以根据需要进行比较或还原。 换句话说,它使您能够查看甚至还原源代码的早期版本。

Repository(Repo)A Repository keeps the track of all changes made to files in your project and builds history over time. Git repository .git/ is a special folder present at the root level of a project. Local Repository — refers to the repository on your computer or the local machineRemote Repository — refers to the repository on a server (Github).

Repository(Repo) Repository跟踪项目中对文件所做的所有更改,并建立历史记录。 Git仓库.git/是项目根.git/下的一个特殊文件夹。 本地存储库-指计算机或本地计算机上的存储库远程存储库-指服务器( Github )上的存储库。

.git/will be a hidden folder inside your current folder.If you delete this folder then this will delete the project history.

.git/将是当前文件夹中的隐藏文件夹。如果删除此文件夹,则将删除项目历史记录。

Master branchWhen a repository is created, Git automatically creates a master branch. By convention, developers use the master branch to be the base copy of the source code, and all the code that is being written in different branches (feature, hotfix, bugfix) will eventually be merged into the master branch, and it could represent the current released version of the application being developed. As such there are no restrictions on branch names. You can call your branches anything that you would like.

Master分支创建存储库后,Git会自动创建一个master分支。 按照惯例,开发人员使用master分支作为源代码的基础副本,并且在不同分支( 功能,修补程序,bugfix )中编写的所有代码最终都将合并到master分支中,并且可以表示正在开发的应用程序的当前发行版本。 因此,分支名称没有限制。 您可以根据需要给分支机构打电话。

Feature branch or Develop branch It has no difference from the master branch or the base code. It’s just a clone of source code which we have check-out or created from the stable version of the code. Let’s take an example to understand why do you need a feature or separate working branch. You are working on a new feature for a website and you are making changes directly in the master branch. While working on the new feature, you got a task to fix an issue and that has to be fixed today itself. Now you can’t push your incomplete new feature task for deployment and at the time you have to push the fixed issue for the deployment. To prevent these situations, you should create a separate working branch for every task. You will create a new feature branch and a bugfix branch from the master or base code. With these separate branches, you will be able to keep your every task in a separate branch and that can be merged in the master branch according to the need without affecting other tasks.

Feature分支或Develop分支与master分支或基本代码没有区别。 它只是源代码的克隆,我们已经签出或从稳定版本的代码创建。 让我们举一个例子来理解为什么需要功能或单独的工作分支。 您正在开发网站的新功能,并且直接在master分支中进行更改。 在使用新功能时,您需要解决一个问题,而该问题今天必须自己解决。 现在,您无法将不完整的新功能任务推送给部署,而此时您必须推送已解决的已发布问题。 为避免这些情况,您应该为每个任务创建一个单独的工作分支。 您将从主代码或基本代码创建一个新的功能分支和一个错误修正分支。 使用这些单独的分支,您将能够将每个任务保留在单独的分支中,并且可以根据需要将其合并到master分支中,而不会影响其他任务。

Image for post
In the local repository, HEAD points to the current checkout branch(testing).
在本地存储库中,HEAD指向当前的结帐分支(测试)。

HeadGit Head is a pointer or reference variable which point to a specific commit in the repository. As we make new commits, the pointer(Head) is going to change or move to point to a new commit in the repository. In the currently check-out branch, Head always point to the last commit.

Head Git Head是一个指针或引用变量,它指向存储库中的特定提交。 在进行新提交时,pointer(Head)将更改或移动以指向存储库中的新提交。 在当前签出分支中,Head始终指向最后一次提交。

Unstaged Area / Untracked FilesChanges made in the working directory(or branch) that are not handled by Git are refreshed as untracked files or unstaged files. These changes can’t be committed.

未暂存区域/未跟踪文件在工作目录(或分支)中未由Git处理的更改将刷新为未暂存文件或未暂存文件。 这些更改无法提交。

Image for post
Working tree, staging area, and Git directory
工作树,暂存区和Git目录

Staged Area / Tracked FilesThe action of adding files or changes we want in the next commit or next version of the code. This is how Git knows what’s gonna change between your current commit and your next commit.With the help of the staged area, you can move only those changes or files that you want in the next commit or next version of the code and the rest can be in the unstaged area.

暂存区/跟踪文件在下一次提交或下一个版本的代码中添加文件或更改所需操作。 这就是Git知道当前提交和下一次提交之间要更改的方式。借助暂存区,您可以仅移动下一次提交或下一版本代码中所需的更改或文件,其余的可以在无舞台区域。

Committing(creates a new version of the code)The action of storing the changes added in the staging area in the local Git Repository. The changes added to the local Git Repository will not be reflected in the remote Git Repository until we push these commit.

Committing( 创建代码的新版本 )将添加的更改存储在本地Git存储库的暂存区中的操作。 除非我们推送这些提交,否则添加到本地Git存储库中的更改将不会反映在远程Git存储库中。

Image for post
The HEAD pointer moves forward when a commit is made.
提交时,HEAD指针会向前移动。

Pushing The action of uploading your local Git commits to the remote(online) repository on Github.

推送上传本地Git的操作将提交到Github上的remote( online )存储库。

Pulling The action of downloading the remote(online) Github commits and bringing them into your local machine.

拉动下载远程( 在线 )Github的操作并将其带入本地计算机。

Pull Request(PR)A Github feature that allows users to easily see the changes (the difference or “diff”) that a feature branch is proposing as well as discuss any tweaks that said branch might require before it is merged into master

Pull Request(PR) Github功能,允许用户轻松查看功能分支提出的更改(差异或“差异”),并讨论在合并到主分支之前该分支可能需要进行的任何调整

Merging The action of taking the commits from a feature branch and adding them to the top of specified branch history and changing the Head to the last commit(that the last commit in the feature branch).

合并从功能分支获取提交并将其添加到指定分支历史记录的顶部,并将Head更改为最后一个提交( 即功能分支中的最后一个提交 )的操作。

Check-out The action of moving from one branch to another.

签出从一个分支移动到另一个分支的动作。

以下是一些常用的Git命令的列表: (Here is the list of the some of the commonly used Git commands :)

  • Clone — used to create a copy of an existing Git repository.

    克隆-用于创建现有Git存储库的副本。

    Clone — used to create a copy of an existing Git repository.$ git clone <repository name>

    克隆-用于创建现有Git存储库的副本。 $ git clone <repository name>

  • Add — add changed files to the staging area and that can be saved in the git repository via committing.

    添加—将更改的文件添加到暂存区,可以通过提交将其保存在git存储库中。

    adding a specific changed file to the staging —

    在登台中添加特定的更改文件-

    $ git add <file-name>

    $ git add <file-name>

    add all the changed files to the staging —

    将所有更改的文件添加到暂存中—

    $ git add .

    $ git add .

  • Status — show the status of the working tree(staged or unstaged files) such as which files have recently been modified.

    状态-显示工作树(已暂存或未暂存的文件)的状态,例如最近修改过的文件。

    Status — show the status of the working tree(staged or unstaged files) such as which files have recently been modified.$ git status

    状态-显示工作树(已暂存或未暂存的文件)的状态,例如最近修改过的文件。 $ git status

  • Commit — save your changes to the local Git repository.

    提交-将更改保存到本地Git存储库。

    Commit — save your changes to the local Git repository.$ git commit -m “commit message eg- initial commit”

    提交-将更改保存到本地Git存储库。 $ git commit -m “commit message eg- initial commit”

  • Push uploading local changes to a specific remote branch.

    推送 将本地更改上传到特定的远程分支。

    Push uploading local changes to a specific remote branch.$ git push origin <remote branch name>

    推送 将本地更改上传到特定的远程分支。 $ git push origin <remote branch name>

  • Pull — to download and integrate remote branch changes in your local branch.

    拉—在本地分支中下载和集成远程分支更改。

    Pull — to download and integrate remote branch changes in your local branch.$ git pull origin <remote branch name>

    拉—在本地分支中下载和集成远程分支更改。 $ git pull origin <remote branch name>

  • Branch — create a new pointer head on the commits.

    分支-在提交上创建一个新的指针头。

    Branch — create a new pointer head on the commits.$ git branch <branch-name>

    分支-在提交上创建一个新的指针头。 $ git branch <branch-name>

  • Check-out — used for branch changing.

    签出-用于分支更改。

    change branch only —

    仅更改分支—

    $ git checkout <branch-name>

    $ git checkout <branch-name>

    changing and creating branch —

    更改和创建分支—

    $ git checkout -b <branch-name>

    $ git checkout -b <branch-name>

  • Merge — its way of putting a forked history back together again. In other words, it integrates the 1 branch with the other branch. For example, merging the feature branch into the master branch.

    合并-一种将分叉的历史重新组合在一起的方式。 换句话说,它将第一个分支与另一个分支集成在一起。 例如,将要素分支合并到master分支中。

    Merge — its way of putting a forked history back together again. In other words, it integrates the 1 branch with the other branch. For example, merging the feature branch into the master branch.$ git merge <branch-name>

    合并-一种将分叉的历史重新组合在一起的方式。 换句话说,它将第一个分支与另一个分支集成在一起。 例如,将要素分支合并到master分支中。 $ git merge <branch-name>

  • Delete — remove pointer head from the commits.

    删除-从提交中删除指针头。

    local branch deletion —

    本地分支删除—

    $ git branch -d <branch-name>

    $ git branch -d <branch-name>

    remote branch deletion —

    远程分支删除—

    $ git push origin --delete <branch-name

    $ git push origin --delete <branch-name

  • Rename — branch renaming.

    重命名-分支重命名。

    rename current branch —

    重命名当前分支—

    git branch -m <branch-name>

    git branch -m <branch-name>

    rename branch while pointed to any branch —

    重命名分支,同时指向任何分支—

    git branch -m <old-branch-name> <new-branch-name>

    git branch -m <old-branch-name> <new-branch-name>

I hope this article is useful to you. Thanks for reading, and keep learning!

希望本文对您有所帮助。 感谢您的阅读,并继续学习!

翻译自: https://medium.com/swlh/things-about-git-and-github-you-need-to-know-as-developer-907baa0bed79

github 和git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值