了解 Git 和 GitHub 的基础知识
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11816424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Understanding the basics of Git and GitHub
提问by fs_tigre
I don't fully understand the purpose of using Git or Github; I know it helps to keep track of your changes and it's helpful for people collaborating with other people, but I don't collaborate with anybody so I don't know if this would be helpful for me.
我不完全理解使用 Git 或 Github 的目的;我知道跟踪您的更改有助于人们与其他人合作,但我不与任何人合作,所以我不知道这对我是否有帮助。
I usually work as a web designer/developer but I never have to collaborate. I know in Git you have create, push, commit, create branches etc for every repository but...
我通常担任网页设计师/开发人员,但我从不需要合作。我知道在 Git 中你为每个存储库创建、推送、提交、创建分支等,但是......
What is the difference between Git and GitHub?
Is git saving every repository locally (in the user's machine) and in GitHub?
Can you use Git without GitHub? If yes, what would be the benefit for using GitHub?
How does Git compare to a backup system such as Time Machine?
Is this a manual process, in other words if you don't commit you wont have a new version of the changes made?
If are not collaborating and you are already using a backup system why would you use Git?
Git 和 GitHub 有什么区别?
git 是否在本地(在用户的机器中)和 GitHub 中保存每个存储库?
你能在没有 GitHub 的情况下使用 Git 吗?如果是,使用 GitHub 有什么好处?
Git 与 Time Machine 等备份系统相比如何?
这是一个手动过程,换句话说,如果您不提交,您将不会有所做更改的新版本?
如果不合作并且您已经在使用备份系统,为什么还要使用 Git?
回答by Davoud Taghawi-Nejad
What is the difference between Git and GitHub?
Git is a version control system; think of it as a series of snapshots(commits) of your code. You see a path of these snapshots, in which order they where created. You can make branches to experiment and come back to snapshots you took.
GitHub, is a web-page on which you can publish your Git repositories and collaborate with other people.
Is Git saving every repository locally (in the user's machine) and in GitHub?
No, it's only local. You can decide to push (publish) some branches on GitHub.
Can you use Git without GitHub? If yes, what would be the benefit for using GitHub?
Yes, Git runs local if you don't use GitHub. An alternative to using GitHub could be running Git on files hosted on Dropbox, but GitHub is a more streamlined service as it was made especially for Git.
How does Git compare to a backup system such as Time Machine?
It's a different thing, Git lets you track changes and your development process. If you use Git with GitHub, it becomes effectively a backup. However usually you would not push all the time to GitHub, at which point you do not have a full backup if things go wrong. I use git in a folder that is synchronized with Dropbox.
Is this a manual process, in other words if you don't commit you won't have a new version of the changes made?
Yes, committing and pushing are both manual.
If are not collaborating and you are already using a backup system why would you use Git?
If you encounter an error between commits you can use the command
git diff
to see the differences between the current code and the last working commit, helping you to locate your error.You can also just go back to the last working commit.
If you want to try a change, but are not sure that it will work. You create a branch to test you code change. If it works fine, you merge it to the main branch. If it does not you just throw the branch away and go back to the main branch.
You did some debugging. Before you commit you always look at the changes from the last commit. You see your debug print statement that you forgot to delete.
Git 和 GitHub 有什么区别?
Git 是一个版本控制系统;将其视为代码的一系列快照(提交)。您会看到这些快照的路径,按照它们创建的顺序。您可以创建分支进行实验并返回到您拍摄的快照。
GitHub 是一个网页,您可以在该网页上发布您的 Git 存储库并与其他人协作。
Git 是否在本地(在用户的机器中)和 GitHub 中保存每个存储库?
不,这只是本地的。您可以决定在 GitHub 上推送(发布)一些分支。
你能在没有 GitHub 的情况下使用 Git 吗?如果是,使用 GitHub 有什么好处?
是的,如果您不使用 GitHub,Git 会在本地运行。使用 GitHub 的另一种方法是在 Dropbox 上托管的文件上运行 Git,但 GitHub 是一种更简化的服务,因为它是专门为 Git 设计的。
Git 与 Time Machine 等备份系统相比如何?
这是另一回事,Git 可让您跟踪更改和开发过程。如果您将 Git 与 GitHub 一起使用,它就变成了有效的备份。然而,通常你不会一直推送到 GitHub,此时如果出现问题,你没有完整的备份。我在与 Dropbox 同步的文件夹中使用 git。
这是一个手动过程,换句话说,如果您不提交,您将不会有所做更改的新版本?
是的,提交和推送都是手动的。
如果不合作并且您已经在使用备份系统,为什么还要使用 Git?
如果在两次提交之间遇到错误,您可以使用该命令
git diff
查看当前代码与上次工作提交之间的差异,帮助您定位错误。您也可以回到上次工作提交。
如果您想尝试更改,但不确定它是否会起作用。您创建一个分支来测试您的代码更改。如果它工作正常,则将其合并到主分支。如果没有,您只需将分支扔掉并返回主分支。
你做了一些调试。在提交之前,您总是会查看上次提交的更改。您会看到忘记删除的调试打印语句。
Make sure you check gitimmersion.com.
确保您检查gitimmersion.com。
回答by fs_tigre
What is the difference between Git and GitHub?
Linus Torvalds would kill you for this. Git is the name of the version manager program he wrote. GitHub is a website on which there are source code repositories manageable by Git. Thus, GitHub is completely unrelated to the original Git tool.
Is git saving every repository locally (in the user's machine) and in GitHub?
If you commit changes, it stores locally. Then, if you push the commits, it also sotres them remotely.
Can you use Git without GitHub? If yes, what would be the benefit for using GitHub?
You can, but I'm sure you don't want to manually set up a git server for yourself. Benefits of GitHub? Well, easy to use, lot of people know it so others may find your code and follow/fork it to make improvements as well.
How does Git compare to a backup system such as Time Machine?
Git is specifically designed and optimized for source code.
Is this a manual process, in other words if you don't commit you wont have a new version of the changes made?
Exactly.
If are not collaborating and you are already using a backup system why would you use Git?
See #4.
Git 和 GitHub 有什么区别?
Linus Torvalds 会因此而杀了你。Git 是他编写的版本管理器程序的名称。GitHub 是一个网站,其中包含可由 Git 管理的源代码存储库。因此,GitHub 与原始 Git 工具完全无关。
git 是否在本地(在用户的机器中)和 GitHub 中保存每个存储库?
如果您提交更改,它会存储在本地。然后,如果您推送提交,它也会远程解决它们。
你能在没有 GitHub 的情况下使用 Git 吗?如果是,使用 GitHub 有什么好处?
您可以,但我确定您不想为自己手动设置 git 服务器。GitHub 的好处?好吧,易于使用,很多人都知道它,因此其他人可能会找到您的代码并关注/分叉它以进行改进。
Git 与 Time Machine 等备份系统相比如何?
Git 是专门为源代码设计和优化的。
这是一个手动过程,换句话说,如果您不提交,您将不会有所做更改的新版本?
确切地。
如果不合作并且您已经在使用备份系统,为什么还要使用 Git?
见#4。
回答by Kevin Markham
What is the difference between Git and GitHub?
Git is a distributed version control system. It usually runs at the command line of your local machine. It keeps track of your files and modifications to those files in a "repository" (or "repo"), but only when you tell it to do so. (In other words, you decide which files to track and when to take a "snapshot" of any modifications.)
In contrast, GitHub is a website that allows you to publish your Git repositories online, which can be useful for many reasons (see #3).
Is Git saving every repository locally (in the user's machine) and in GitHub?
Git is known as a "distributed" (rather than "centralized") version control systembecause you can run it locally and disconnected from the Internet, and then "push" your changes to a remote system (such as GitHub) whenever you like. Thus, repo changes only appear on GitHub when you manuallytell Git to push those changes.
Can you use Git without GitHub? If yes, what would be the benefit for using GitHub?
Yes, you can use Git without GitHub. Git is the "workhorse" program that actually tracks your changes, whereas GitHub is simply hosting your repositories (and provides additional functionality not available in Git). Here are some of the benefits of using GitHub:
- It provides a backup of your files.
- It gives you a visual interface for navigating your repos.
- It gives other people a way to navigate your repos.
- It makes repo collaboration easy (e.g., multiple people contributing to the same project).
- It provides a lightweight issue tracking system.
How does Git compare to a backup system such as Time Machine?
Git does backup your files, though it gives you much more granular controlthan a traditional backup system over what and when you backup. Specifically, you "commit" every time you want to take a snapshot of changes, and that commit includes both a description of your changes and the line-by-line details of those changes. This is optimal for source code because you can easily see the change history for any given file at a line-by-line level.
Is this a manual process, in other words if you don't commit you won't have a new version of the changes made?
Yes, this is a manual process.
If are not collaborating and you are already using a backup system why would you use Git?
- Git employs a powerful branching systemthat allows you to work on multiple, independent lines of development simultaneously and then merge those branches together as needed.
- Git allows you to view the line-by-line differences between different versions of your files, which makes troubleshooting easier.
- Git forces you to describe each of your commits, which makes it significantly easier to track down a specific previous version of a given file (and potentially revert to that previous version).
- If you ever need help with your code, having it tracked by Git and hosted on GitHub makes it much easier for someone else to look at your code.
Git 和 GitHub 有什么区别?
Git 是一个分布式版本控制系统。它通常在本地机器的命令行中运行。它会在“存储库”(或“存储库”)中跟踪您的文件和对这些文件的修改,但前提是您告诉它这样做。(换句话说,您决定要跟踪哪些文件以及何时对任何修改进行“快照”。)
相比之下,GitHub 是一个允许您在线发布 Git 存储库的网站,这有很多用途(参见 #3)。
Git 是否在本地(在用户的机器中)和 GitHub 中保存每个存储库?
Git 被称为“分布式”(而不是“集中式”)版本控制系统,因为您可以在本地运行它并断开与 Internet 的连接,然后随时将您的更改“推送”到远程系统(例如 GitHub)。因此,只有当您手动告诉 Git 推送这些更改时,repo 更改才会出现在 GitHub 上。
你能在没有 GitHub 的情况下使用 Git 吗?如果是,使用 GitHub 有什么好处?
是的,您可以在没有 GitHub 的情况下使用 Git。Git 是实际跟踪您的更改的“主力”程序,而 GitHub 只是托管您的存储库(并提供 Git 中不可用的附加功能)。以下是使用 GitHub 的一些好处:
- 它为您的文件提供备份。
- 它为您提供了一个用于导航存储库的可视化界面。
- 它为其他人提供了一种导航您的存储库的方法。
- 它使 repo 协作变得容易(例如,多人为同一个项目做出贡献)。
- 它提供了一个轻量级的问题跟踪系统。
Git 与 Time Machine 等备份系统相比如何?
Git 确实会备份您的文件,尽管与传统的备份系统相比,它可以让您更精细地控制备份的内容和时间。具体来说,您每次想要获取更改快照时都“提交”,并且该提交包括对更改的描述和这些更改的逐行详细信息。这是源代码的最佳选择,因为您可以轻松地逐行查看任何给定文件的更改历史记录。
这是一个手动过程,换句话说,如果您不提交,您将不会有所做更改的新版本?
是的,这是一个手动过程。
如果不合作并且您已经在使用备份系统,为什么还要使用 Git?
- Git 采用了强大的分支系统,允许您同时处理多个独立的开发线,然后根据需要将这些分支合并在一起。
- Git 允许您查看文件的不同版本之间的逐行差异,这使得故障排除更容易。
- Git 强制您描述每个提交,这使得跟踪给定文件的特定先前版本(并可能恢复到该先前版本)变得更加容易。
- 如果您需要代码方面的帮助,让 Git 跟踪并托管在 GitHub 上可以让其他人更轻松地查看您的代码。
For getting started with Git, I recommend the online book Pro Gitas well as GitRefas a handy reference guide. For getting started with GitHub, I like the GitHub's Bootcampand their GitHub Guides. Finally, I created a short videos seriesto introduce Git and GitHub to beginners.
为了开始使用 Git,我推荐在线书籍Pro Git和GitRef作为方便的参考指南。为了开始使用 GitHub,我喜欢GitHub 的训练营和他们的GitHub 指南。最后,我创建了一个简短的视频系列,向初学者介绍 Git 和 GitHub。