Download Pragmatic Version Control Using Git PDF

TitlePragmatic Version Control Using Git
LanguageEnglish
File Size5.0 MB
Total Pages184
Table of Contents
                            Contents
Acknowledgments
Preface
	Who's This Book For?
	What's in This Book?
	Typographic Conventions
	Online Resources
Welcome to the Distributed World
	Version Control the Git Way
		The Repository
		What Should You Store?
		Working Trees
		Manipulating Files and Staying in Sync
		Tracking Projects, Directories, and Files
		Tracking Milestones with Tags
		Creating Alternate Histories with Branches
		Merging
		Locking Options
		Next Steps
	Setting Up Git
		Installing Git
		Configuring Git
		Using Git's GUI
		Accessing Git's Built-in Help
	Creating Your First Project
		Creating a Repository
		Making Changes
		Starting to Work with a Project
		Using and Understanding Branches
		Handling Releases
		Cloning a Remote Repository
Everyday Git
	Adding and Committing: Git Basics
		Adding Files
		Committing Changes
		Seeing What Has Changed
		Managing Files
	Understanding and Using Branches
		What Are Branches?
		Creating a New Branch
		Merging Changes Between Branches
		Handling Conflicts
		Deleting Branches
		Renaming Branches
	Working with Git's History
		Inspecting Git's Log
		Specifying Revision Ranges
		Looking at Differences Between Versions
		Finding Out Who's to Blame
		Following Content
		Undoing Changes
		Rewriting History
	Working with Remote Repositories
		Network Protocols
		Cloning a Remote Repository
		Keeping Up-to-Date
		Pushing Changes
		Adding New Remote Repositories
	Organizing Your Repository
		Marking Milestones with Tags
		Handling Release Branches
		Using Valid Names for Tags and Branches
		Tracking Multiple Projects
		Using Git Submodules to Track External Repositories
	Beyond the Basics
		Compacting Repository History
		Exporting Your Repository
		Rebasing a Branch
		Using the Reflog
		Bisecting Your Repository
Administration
	Migrating to Git
		Communicating with SVN
		Making Sure git-svn Is Available
		Importing a Subversion Repository
		Keeping Up-to-Date with a Subversion Repository
		Pushing Changes to SVN
		Importing from CVS
	Running a Git Server with Gitosis
		Making Sure Dependencies Are Met
		Installing Gitosis
		Creating Administrator Credentials
		Configuring the Server for Gitosis
		Initializing Gitosis
		Configuring Gitosis
		Adding New Repositories
		Setting Up a Public Repository
		Closing Thoughts
Appendixes
	Git Command Quick Reference
		Setup and Initialization
		Normal Usage
		Branches
		History
		Remote Repositories
		Git to SVN Bridge
	Other Resources and Tools
		Extras Bundled with Git
		Third-Party Tools
		Git Repository Hosting
		Online Resources
	Bibliography
Index
	A
	B
	C
	D
	E
	F
	G
	H
	I
	K
	L
	M
	N
	O
	P
	R
	S
	T
	U
	V
	W
                        
Document Text Contents
Page 1

Prepared exclusively for Trieu Nguyen

Page 2

What readers are saying about Pragmatic Version Control

Using Git

Pragmatic Version Control Using Git is an excellent guide to getting you

started with Git. It will teach you not only how to get yourself started

but also how to cooperate with others and how to keep your history

clean.

Pieter de Bie

Author, GitX

If you are thinking of using Git, I highly recommend this book. If you

are not using a version control system (and code or create content on

a computer), put the book down, slap yourself, pick the book back up,

and buy it.

Jacob Taylor

Entrepreneur and Cofounder, SugarCRM Inc.

Not only has this book convinced me that Git has something to offer

over CVS and Subversion, but it has also showed me how I can benefit

from using it myself even if I’m using it alone in a CVS/Subversion

environment. I expect to be a full-time Git user soon after reading

this, which is hard to believe considering this is the first distributed

version control system I’ve ever looked at.

Chuck Burgess

2008 PEAR Group Member

Travis has done an excellent job taking a tricky subject and making it

accessible, useful, and relevant. You’ll find distributed version control

and Git much less mysterious after reading this book.

Mike Mason

Author, Pragmatic Version Control Using Subversion

Prepared exclusively for Trieu Nguyen

Download at Boykma.Com

Page 92

UNDOING CHANGES 92

When you push changes, then change your history, and push those

changes that are different, you can cause problems for people who

already have the first set of changes you published. For more infor-

mation on pushing changes, see Section 7.4, Pushing Changes, on

page 105.

Now that we’ve covered the dangers in what we’re about do to, let’s get

to the good stuff. Up first, amending commits.

Amending Commits

We’ve all been there. You’re writing code in a new, still sort of unfamil-

iar language and forget a full stop at the end of a line or leave off a

semicolon.3

Correcting these small problems with Git is simple. Make the correc-

tion, stage the change, and add --amend when you commit.

To demonstrate, add a link to your blog or a website you frequent in

your contact.html file, except put a typo in it:

prompt> git commit -m "add link to blog" -a

Created commit c3531c4: add link to blog

1 files changed, 4 insertions(+), 0 deletions(-)

Now, fix the URL and commit the changes again, except add --amend to

the commit command:

prompt> git commit -C HEAD -a --amend

Created commit 45eaf98: add link to blog

1 files changed, 4 insertions(+), 0 deletions(-)

That command introduces a new option to git commit, -C. This option

tells Git to use the log message from the commit specified—in this case

HEAD, but it could have been any valid commit name as well—instead

of explicitly providing a new message. You use the parameter in its

lowercase form, -c, to tell Git to launch the editor with the message

already filled in so you tweak it before finalizing the commit.

Amending a commit should be done only when you are working with

the last commit. If you made a mistake and need to correct it after

other commits have been made, you want to use git revert, which is up

next.

3. Ironically, I had to use --amend when writing this section of the book because I had a

typo in one of the tags and didn’t catch it until after I had committed.

Report erratum

this copy is (P2.0 printing, March 2009)
Prepared exclusively for Trieu Nguyen

Download at Boykma.Com

http://books.pragprog.com/titles/tsgit/errata/add?pdf_page=92

Page 93

UNDOING CHANGES 93

Reverting Commits

Sometimes code doesn’t work out. It requires a certain architecture or

introduces a new third-party software dependency that the rest of the

team isn’t on board with. If you’ve committed your changes already,

you need to undo the commits with the new change, or revert them.

The simplest way to revert an existing commit is the git revert command.

It “reverts” a commit by creating a new commit in your repository that

reverses all the changes made by the original commit.

Normally Git commits the reversal immediately, but you can add the

-n parameter to tell Git not to commit. This is useful when you need

to revert multiple commits. Just run multiple git revert commands with

the -n parameter, and Git stages all the changes and waits for you to

commit them.

You must provide it with a commit name so it knows what to revert. For

example, if you wanted to revert the commit 540ecb7 and HEAD, use the

following. Always revert backward—the most recent first. That makes

sure you don’t have any unnecessary conflicts to work through when

reverting multiple commits.

prompt> git revert -n HEAD

Finished one revert.

prompt> git revert -n 540ecb7

Removed copy.txt

Finished one revert.

prompt> git commit -m "revert 45eaf98 and 540ecb7"

Created commit 2b3c1de: revert 45eaf98 and 540ecb7

2 files changed, 0 insertions(+), 10 deletions(-)

delete mode 100644 copy.txt

By default, git revert starts up your editor for your commit message.

The default message is added to the editor: Revert "your original log mes-

sage" followed by the text This reverts commit <commit name>. You can add

--no-edit to git revert when you want it to use the default message.

Just like any other commit, make sure you explain why you’re making

this commit. Just marking that you’re reverting a change, like I did

here, doesn’t say much.

Did it not work? Was it too slow? Say that. You’ll thank yourself in six

months when you’re trying to remember why you reverted that change.

Report erratum

this copy is (P2.0 printing, March 2009)
Prepared exclusively for Trieu Nguyen

Download at Boykma.Com

http://books.pragprog.com/titles/tsgit/errata/add?pdf_page=93

Page 183

Stuff You Need to Know
Learn the best ways to use your own brain and the best ways to use Ubuntu Linux. Either

way, this is stuff you need to know.

Pragmatic Thinking and Learning
Software development happens in your head. Not in

an editor, IDE, or design tool. In this book by

Pragmatic Programmer Andy Hunt, you’ll learn how

our brains are wired, and how to take advantage of

your brain’s architecture. You’ll master new tricks

and tips to learn more, faster, and retain more of

what you learn.

• Use the Dreyfus Model of Skill Acquisition to

become more expert • Leverage the architecture of

the brain to strengthen different thinking modes

• Avoid common “known bugs” in your mind

• Learn more deliberately and more effectively

• Manage knowledge more efficiently

Pragmatic Thinking and Learning:

Refactor your Wetware

Andy Hunt

(288 pages) ISBN: 978-1-9343560-5-0. $34.95

http://pragprog.com/titles/ahptl

Ubuntu Kung Fu
Award-winning Linux author Keir Thomas gets

down and dirty with Ubuntu to provide over 300

concise tips that enhance productivity, avoid

annoyances, and simply get the most from Ubuntu.

You’ll find many unique tips here that can’t be

found anywhere else.

You’ll also get a crash course in Ubuntu’s flavor of

system administration. Whether you’re new to

Linux or an old hand, you’ll find tips to make your

day easier.

This is the Linux book for the rest of us.

Ubuntu Kung Fu: Tips, Tricks, Hints, and Hacks

Keir Thomas

(400 pages) ISBN: 978-1-9343562-2-7. $34.95

http://pragprog.com/titles/ktuk

Prepared exclusively for Trieu Nguyen

Download at Boykma.Com

http://pragprog.com/titles/ahptl
http://pragprog.com/titles/ktuk

Page 184

The Pragmatic Bookshelf
The Pragmatic Bookshelf features books written by developers for developers. The titles

continue the well-known Pragmatic Programmer style and continue to garner awards and

rave reviews. As development gets more and more difficult, the Pragmatic Programmers

will be there with more titles and products to help you stay on top of your game.

Visit Us Online
Pragmatic Version Control Using Git’s Home Page

http://pragprog.com/titles/tsgit

Source code from this book, errata, and other resources. Come give us feedback, too!

Register for Updates

http://pragprog.com/updates

Be notified when updates and new books become available.

Join the Community

http://pragprog.com/community

Read our weblogs, join our online discussions, participate in our mailing list, interact

with our wiki, and benefit from the experience of other Pragmatic Programmers.

New and Noteworthy

http://pragprog.com/news

Check out the latest pragmatic developments in the news.

Buy the Book
If you liked this PDF, perhaps you’d like to have a paper copy of the book. It’s available

for purchase at our store: pragprog.com/titles/tsgit.

Contact Us
Phone Orders: 1-800-699-PROG (+1 919 847 3884)

Online Orders: www.pragprog.com/catalog

Customer Service: [email protected]

Non-English Versions: [email protected]

Pragmatic Teaching: [email protected]

Author Proposals: [email protected]

Prepared exclusively for Trieu Nguyen

Download at Boykma.Com

http://pragprog.com/titles/tsgit
http://pragprog.com/updates
http://pragprog.com/community
http://pragprog.com/news
pragprog.com/titles/tsgit
www.pragprog.com/catalog

Similer Documents