Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

git - Git初学者:权威的实用指南(Git for beginners: The definitive practical guide)

Ok, after seeing this post by PJ Hyett , I have decided to skip to the end and go with Git . (好的,在看到PJ Hyett的这篇文章之后,我决定跳到最后,选择Git 。)

So what I need is a beginner's practical guide to Git. (因此,我需要的是Git的初学者实用指南。) "Beginner" being defined as someone who knows how to handle their compiler, understands to some level what a Makefile is, and has touched source control without understanding it very well. (“初学者”被定义为知道如何处理其编译器,在某种程度上理解Makefile是什么,并且在不十分了解它的情况下接触了源代码控制的人。)

"Practical" being defined as this person doesn't want to get into great detail regarding what Git is doing in the background, and doesn't even care (or know) that it's distributed. (“实用”被定义为该人员不想深入了解Git在后台执行的操作,甚至不关心(或知道)它的分发。) Your answers might hint at the possibilities, but try to aim for the beginner that wants to keep a 'main' repository on a 'server' which is backed up and secure, and treat their local repository as merely a 'client' resource. (您的答案可能暗示了这种可能性,但请尝试针对希望将“主”存储库保留在已备份且安全的“服务器”上的初学者,并将其本地存储库视为“客户端”资源。)

So: (所以:)

Installation/Setup (安装/设置)

Working with the code (使用代码)

Tagging, branching, releases, baselines (标记,分支,发布,基准)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

How do you create a new project/repository? (如何创建新的项目/存储库?)

A git repository is simply a directory containing a special .git directory. (git存储库只是一个包含特殊.git目录的目录。)

This is different from "centralised" version-control systems (like subversion), where a "repository" is hosted on a remote server, which you checkout into a "working copy" directory. (这与“集中式”版本控制系统(如Subversion)不同,在“集中式”版本控制系统中,“存储库”托管在远程服务器上,您可以将其checkout到“工作副本”目录中。) With git, your working copy is the repository. (使用git,您的工作副本就是存储库。)

Simply run git init in the directory which contains the files you wish to track. (只需在包含您要跟踪的文件的目录中运行git init 。)

For example, (例如,)

cd ~/code/project001/
git init

This creates a .git (hidden) folder in the current directory. (这将在当前目录中创建一个.git (隐藏)文件夹。)

To make a new project, run git init with an additional argument (the name of the directory to be created): (要创建一个新项目,请使用附加参数(要创建的目录的名称)运行git init :)

git init project002

(This is equivalent to: mkdir project002 && cd project002 && git init)

To check if the current current path is within a git repository, simply run git status - if it's not a repository, it will report "fatal: Not a git repository" (要检查当前当前路径是否在git存储库中,只需运行git status如果它不是存储库,它将报告“严重:不是git存储库”)

You could also list the .git directory, and check it contains files/directories similar to the following: (您还可以列出.git目录,并检查它是否包含类似于以下内容的文件/目录:)

$ ls .git
HEAD         config       hooks/       objects/
branches/    description  info/        refs/

If for whatever reason you wish to "de-git" a repository (you wish to stop using git to track that project). (如果出于某种原因您希望“解散”存储库(您希望停止使用git跟踪该项目)。) Simply remove the .git directory at the base level of the repository. (只需在存储库的基础级别上删除.git目录。)

cd ~/code/project001/
rm -rf .git/

Caution: This will destroy all revision history, all your tags, everything git has done. (注意:这将销毁所有修订历史记录, 所有标签以及git所做的所有事情。) It will not touch the "current" files (the files you can currently see), but previous changes, deleted files and so on will be unrecoverable! (它不会触摸“当前”文件(您当前可以看到的文件),但是以前的更改,已删除的文件等将无法恢复!)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...