`
wbj0110
  • 浏览: 1613225 次
  • 性别: Icon_minigender_1
  • 来自: 上海
文章分类
社区版块
存档分类
最新评论

git tutorial

阅读更多

introduction

I’ve been working with a group of people known as qworky making some cool meeting software for all y’all. A few people on the team aren’t too familiar with distributed version control systems, so I wrote up a little tutorial on git for them, and since I’m such a kind and generous guy, I’ve decided to share it with the internets. Enjoy.

basic commands

Before we begin, I recommend printing out a copy of this cheat sheet and putting it somehere handy. Also, if any of this makes your brain hurt, try spending some time looking at the git community book.

First, let’s get our very own copy of the ‘qworky-kickstart’ repository.

git clone git://github.com/billputer/qworky-kickstart.git

Now, you should have a folder called qworky-kickstart. Let’s check it out.

cd qworky-kickstart
git status

You should see the following output.

# On branch master
nothing to commit (working directory clean)

That’s good, it means we’ve got a clean slate. Let’s look a bit at the previous changes.

git log

Interesting stuff, eh? Now, let’s set aside a our own portion of the slate to work on.

git checkout -b bill

This creates a local branch, our own version of history that we can trample all over without worrying about the main timeline of changes. Go ahead, make some changes. Delete some stuff, change all occurences of the word ‘config’ to the word ‘convention’, whatever. Once you’ve done that, try using git status and git diff. See all your changes? Good. However, we don’t want those changes, let’s erase them.

git reset --hard

Reset makes sense, right? You’ve made some changes, but you want to reset to the previous commited version (known as HEAD). But what does the --hard mean? Let’s RTFM.

--hard
Matches the working tree and index to that of the tree being switched to. Any changes to tracked files in the working tree since <commit> are lost.

Working tree? Index? These are two important terms in git. Working tree refers to the actual files and directories that we’re using. If you modify a file in your git repository, you’re almost certainly making a change to the working tree. The index is the grey area between changes to the filesystem and changes commited to the repository. How so? Let me show you an example.

Make more changes to a file. Nothing silly, something you actually want to keep. Comment some code, do something useful. Okay, now you’ve changed the working tree. Good job! Now try the command git status. Okay, it shows that some files are Changed but not updated. Let’s add those to the index. Type git add <filename>. Try git status again. Ahah! Now that the file is in the index, it’s listed under Changes to be committed. Now that we’ve done that, let’s take the plunge and commit something.

git commit -m "Very important changes"

Try git status and git log again. See your commit? Good work, you’ve now made a commit to your local repository. What? You still don’t know what the index is!? Let me explain. The index is where you put changes that you’re about to commit. Why would you want this seemingly extra step? Well, the index is there in case you only want to commit one or two of your changes. The git commit -m only commits files in the index, so you only have to git add the files that you want to commit. Still doesn’t make sense? Just remember that commiting a change is a two-step process, first you git add, then you git commit. The brave can combine those two with git commit -a, which commits all of the Changed but not updated files.

git for collaboration

So now we’ve made some changes to the bill branch of our local repository. That’s great, but we’re using git because we want to collaborate. We want our changes to magically appear back on the master branch of the original repsitory we cloned (the origin, in git parlance). This generally involves two steps, merging our changes into the master branch of our local repository, and then pushing our changes up to the origin at github.

There are several ways of moving our changes from the bill branch to the master branch. We could simply make the same changes on the master branch and then commit them, but that’d be silly, since we already have made those commits on the bill branch. Let’s checkout the master branch, and then merge it with the bill branch.

git checkout master
git merge bill

Now we have a local master branch with our changes, and now we want to give those to our colleagues on github. First, let’s make sure we’ve got the most recent copy of the repository so we can resolve any conflicts ourselves.

git pull

This will pull down any changes in our origin repository that have happened since we cloned it, and attempt to merge them with our local changes. This can get messy, and I’ll walk you through the process in a later tutorial. For now we’ll assume that everything went fine and dandy. Let’s finish this.

git push

Assuming you have the proper permissions, this will push your commits back to origin at github, and all your friends will be free to git fetch or git pull them. Good work!

 

come from:http://billwiens.com/technology/yet-another-git-tutorial/

分享到:
评论

相关推荐

    ry's git tutorial

    rys-git-tutorial.epub

    Git - tutorial

    Git - Tutorial Lars Vogel Version 5.7 Copyright © 2009, 2010, 2011, 2012, 2013, 2014 vogella GmbH 14.12.2014 Git Tutorial This tutorial explains the usage of the distributed version control system ...

    Git Tutorial.pdf

    git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程git 教程

    Git Tutorial

    Git是一款分布式版本控制系统,它被广泛用于源代码管理。最初的Git是由Linux的创始人Linus Torvalds为了Linux内核开发而设计和开发的。Git软件是自由软件,遵循GNU通用公共许可证版本2。本教程将介绍如何在分布式...

    gittutorial-Nparti:GitHub课堂创建的gittutorial-Nparti

    Git教程是针对版本控制系统的深度学习资源,特别关注GitHub上创建的"gittutorial-Nparti"项目。这个教程旨在帮助用户全面理解Git的基本概念、命令和工作流程,从而有效地管理和协作开发代码。以下是对Git教程中关键...

    GitTutorial:关于如何在实践中使用 Git 和 Github 的教程

    在 PC 上为此创建一个名为Git Tutorial的新文件夹 在此文件夹中打开 VSCode 创建一个新的README.md文件 里面写Olá, nesse projeto você aprenderá alguns comandos do Git 保存文件 所以现在是使用 Git 的时候...

    gittutorial:学习使用git

    这篇教程“gittutorial”旨在帮助初学者理解Git的基础操作,并掌握其核心概念。 1. **Git基础** - **安装Git**:在不同操作系统上(Windows、macOS、Linux)安装Git,设置用户信息,包括用户名和邮箱,这是Git识别...

    gittutorial:嘿,这是一个 git 教程存储库

    "gittutorial" 存储库显然旨在提供关于 Git 的基础到进阶教程,帮助用户理解和掌握这个强大的工具。在这个教程中,我们可以期待学习如何初始化 Git 仓库、添加文件、提交更改、查看历史记录、分支管理、合并代码以及...

    gitTutorial

    gitTutorial

    GitTutorial

    GitTutorial

    CST316-Lab1GitTutorial:只是一个熟悉命令的GIT练习

    在这个名为"CST316-Lab1GitTutorial"的练习中,主要目的是让学习者熟悉Git的基本命令操作。Git是一款分布式版本控制系统,广泛应用于软件开发,尤其是协作开发中,能够跟踪对项目文件的修改,方便团队成员之间的协作...

    gittutorial-egco:测试拉取请求

    "gittutorial-egco:测试拉取请求"这个标题暗示了我们正在讨论一个与Git教程相关的项目,其中可能涉及到如何进行拉取请求(Pull Request)的实践操作。拉取请求是Git协作流程中的关键步骤,允许开发者将他们的更改...

    GitTutorial:用于学习目的的存储库

    GitTutorial:用于学习目的的存储库

    Git-2.28.0-64-bit.rar

    有关有用的最小命令集,请参阅 gittutorial[7]以开始,然后查看 giteveryal[7]。Git 用户手册有更深入的介绍。 掌握基本概念后,可以回到此页面,了解 Git 提供的命令。您可以使用"git 帮助命令"了解有关单个 Git ...

    GitTutorial:创建此文件是为了学习git命令

    Git教程:掌握基础与进阶命令 Git是一种分布式版本控制系统,由Linus Torvalds为Linux内核开发而创建。它的主要目标是提高版本控制的效率,并提供强大的分支和合并功能,使得多人协作开发变得更加简单。在这个“Git...

    GitTutorial:廖雪峰Git教程Android版本

    Git是目前世界上最先进的分布式版本控制系统,尤其在软件开发领域中被广泛应用。廖雪峰的Git教程是学习Git的优秀资源,现在它已经被移植到了Android平台,使得开发者可以在移动设备上随时随地学习Git。以下是对Git的...

    GitTutorial:在VScode中使用Git的教程

    Git是世界上最流行的分布式版本控制系统,它允许开发者跟踪和管理代码变更,便于团队协作。Visual Studio Code(VSCode)是一款强大的源代码编辑器,内置了Git功能,使得在编辑器内部进行版本控制操作变得非常便捷。...

Global site tag (gtag.js) - Google Analytics