如何使用 Git?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1004936/
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
How to use Git?
提问by Adam Lee
I am an engineering student who spends most of his spare time watching TV rather than coding. So basically I have zero experience with any kind of version control system. My understanding is somehow they make distribution of projects easier.
我是一名工科学生,他的大部分业余时间都花在看电视而不是编码上。所以基本上我对任何类型的版本控制系统都有零经验。我的理解是它们以某种方式使项目的分发更容易。
I was looking into Blueprint CSS Framework, liked it and downloaded from their Git project page. Now, I know Git does much more than providing a link on their website. So my questions are the following:
我正在研究Blueprint CSS Framework,喜欢它并从他们的 Git 项目页面下载。现在,我知道 Git 所做的不仅仅是在他们的网站上提供链接。所以我的问题如下:
- How do I use Git properly to keep my Blueprint download updated? Say there is a new version, what do I do?
- Can I update all Git downloads at the same time? Say I have Blueprint and other projects downloaded on my Mac, how can I update them efficiently?
- 如何正确使用 Git 来更新我的蓝图下载?说有新版本,我该怎么办?
- 我可以同时更新所有 Git 下载吗?假设我在 Mac 上下载了蓝图和其他项目,我该如何有效地更新它们?
I looked into Git guide, but it's mostly for the people who have much more experience than I have.
我查看了 Git 指南,但它主要针对比我有更多经验的人。
Thanks for help :)
感谢帮助 :)
采纳答案by stefanB
Have a look at git for designersfor great one page article/high level intro to the topic. (That link is broken: Here is a link to another Git for Designers)
看看设计师的 git 以获得伟大的一页文章/该主题的高级介绍。(该链接已断开:这是指向另一个 Git for Designers的链接)
I would start at http://git-scm.com/documentation, there are documents and great video presentations for non-software-developer/cs users. Git for beginnershave some basic stuff.
我将从http://git-scm.com/documentation开始,这里有针对非软件开发人员/cs 用户的文档和精彩的视频演示。Git 初学者有一些基本的东西。
回答by stefanB
I really like the O'Reilly book "Version Control with Git". I read it cover-to-cover and now I'm very comfortable with advanced git topics.
我真的很喜欢 O'Reilly 的书“使用 Git 进行版本控制”。我从头到尾阅读了它,现在我对高级 git 主题非常满意。
回答by dragonfly
git clone your-url local-dir
git clone your-url local-dir
to checkout source code;
签出源代码;
git pull
拉
to update source code in local-dir;
更新本地目录中的源代码;
回答by John G
You might want to start with an introduction to version control. This guide is specific to subversion, but the core concepts can be applied to most version control systems. After you have the basics, you can delve into the git guide.
您可能希望从介绍版本控制开始。本指南特定于 Subversion,但核心概念可以应用于大多数版本控制系统。掌握了基础知识后,您可以深入研究 git 指南。
回答by Scott Muc
回答by Ryan Bigg
To answer your questions directly rather than pointing you at documentation:
要直接回答您的问题而不是将您指向文档:
1) In order to keep it up to date, do a git pull and that will pull down the latest changes in the repository, on the branch that you're currently using (which is generally master)
1)为了保持最新状态,请执行 git pull 并在您当前使用的分支(通常是主分支)上拉下存储库中的最新更改
2) I don't think there's something (widely available) that'll do this for you. To update them follow 1) for all projects.
2)我认为没有什么(广泛可用的)可以为您做到这一点。要更新它们,请遵循 1) 所有项目。
回答by Malatesh Patil
Using Git for version control
使用 Git 进行版本控制
Visual studio code have Integrated Git Support.
Visual Studio 代码具有集成的 Git 支持。
- Steps to use git.
- 使用 git 的步骤。
Install Git : https://git-scm.com/downloads
安装 Git:https: //git-scm.com/downloads
1) Initialize your repository
1) 初始化您的存储库
Navigate to directory where you want to initialize Git
导航到要初始化 Git 的目录
Use git initcommand This will create a empty .git repository
使用git init命令这将创建一个空的 .git 存储库
2) Stage the changes
2)阶段性变化
Staging is process of making Git to track our newly added files. For example add a file and type git status. You will find the status that untracked file. So to stage the changes use git add filename. If now type git status, you will find that new file added for tracking.
暂存是使 Git 跟踪我们新添加的文件的过程。例如添加一个文件并输入 git status。您将找到未跟踪文件的状态。因此,要暂存更改,请使用git add filename。如果现在输入 git status,您会发现添加了用于跟踪的新文件。
You can also unstage files. Use git reset
您还可以取消暂存文件。使用 git 重置
3) Commit Changes
3) 提交更改
Commiting is the process of recording your changes to repository. To commit the statges changes, you need to add a comment that explains the changes you made since your previous commit.
提交是将更改记录到存储库的过程。要提交 statges 更改,您需要添加一条注释来解释自上次提交以来所做的更改。
Use git commit -m message string
使用git commit -m 消息字符串
We can also commit the multiple files of same type using command git add '*.txt'. This command will commit all files with txt extension.
我们还可以使用命令git add '*.txt'提交多个相同类型的文件。此命令将提交所有扩展名为 txt 的文件。
4) Follow changes
4) 跟随变化
The aim of using version control is to keep all versions of each and every file in our project, Compare the the current version with last commit and keep the log of all changes.
使用版本控制的目的是保留我们项目中每个文件的所有版本,将当前版本与上次提交进行比较,并保留所有更改的日志。
Use git logto see the log of all changes.
使用git log查看所有更改的日志。
Visual studio code's integrated git support help us to compare the code by double clicking on the file OR Use git diff HEAD
Visual Studio 代码的集成 git 支持帮助我们通过双击文件或使用 git diff HEAD来比较代码
You can also undo file changes at the last commit. Use git checkout -- file_name
您还可以在上次提交时撤消文件更改。使用git checkout --file_name
5) Create remote repositories
5) 创建远程仓库
Till now we have created a local repository. But in order to push it to remote server. We need to add a remote repository in server.
到目前为止,我们已经创建了一个本地存储库。但是为了将其推送到远程服务器。我们需要在服务器中添加一个远程存储库。
Use git remote add origin server_git_url
使用git remote add origin server_git_url
Then push it to server repository
然后将其推送到服务器存储库
Use git push -u origin master
使用git push -u origin master
Let assume some time has passed. We have invited other people to our project who have pulled our changes, made their own commits, and pushed them.
假设已经过了一段时间。我们邀请了其他人加入我们的项目,他们拉动了我们的更改,做出了自己的提交,并推动了他们。
So to get the changes from our team members, we need to pull the repository.
因此,为了从我们的团队成员那里获得更改,我们需要拉取存储库。
Use git pull origin master
使用git pull origin master
6) Create Branches
6) 创建分支
Lets think that you are working on a feature or a bug. Better you can create a copy of your code(Branch) and make separate commits to. When you have done, merge this branch back to their master branch.
让我们认为您正在处理一个功能或错误。更好的是,您可以创建代码的副本(分支)并单独提交。完成后,将此分支合并回其主分支。
Use git branch branch_name
使用git branch branch_name
Now you have two local branches i.e master and XXX(new branch). You can switch branches using git checkout masterOR git checkout new_branch_name
现在你有两个本地分支,即 master 和 XXX(新分支)。您可以使用git checkout master或 git checkout new_branch_name切换分支
Commiting branch changes using git commit -m message
使用git commit -m message 提交分支更改
Switch back to master using git checkout master
使用git checkout master切换回master
Now we need to merge changes from new branch into our master Use git merge branch_name
现在我们需要将新分支的更改合并到我们的主分支中使用git merge branch_name
Good! You just accomplished your bugfix Or feature development and merge. Now you don't need the new branch anymore. So delete it using git branch -d branch_name
好的!您刚刚完成了错误修复或功能开发和合并。现在你不再需要新的分支了。所以使用git branch -d branch_name删除它
Now we are in the last step to push everything to remote repository using git push
现在我们进入了使用git push将所有内容推送到远程存储库的最后一步
Hope this will help you
希望能帮到你
回答by Rajesh Kumaran
this is my blog on git and its for beginners who want to get started on git. https://techxposers.com/git-for-beginners/
这是我关于 git 的博客,它适合想要开始使用 git 的初学者。 https://techxposers.com/git-for-beginners/
回答by Mo.
I would suggest this three for beginners
我会为初学者推荐这三个
http://git-scm.com/docs/gittutorial
http://git-scm.com/docs/gittutorial
https://tutsplus.com/course/git-essentials/(video tutorial)
https://tutsplus.com/course/git-essentials/ (视频教程)
http://lifehacker.com/5983680/how-the-heck-do-i-use-github(gihub)
http://lifehacker.com/5983680/how-the-heck-do-i-use-github (gihub)
回答by Idan
If you wish to update several git repositories in one command - i suggest that you read a little bit on repo.
如果您希望在一个命令中更新多个 git 存储库 - 我建议您阅读有关repo 的一些内容。
About updating the repository, you can do it by:
关于更新存储库,您可以通过以下方式进行:
git fetch
git rebase origin/master
OR
或者
git pull --rebase
For more information about using GIT you can take a look on my GIT beginners guide
有关使用 GIT 的更多信息,您可以查看我的GIT 初学者指南