background preloader

Git

Facebook Twitter

Learn Git Branching. Git. One of the topics that I didn't cover in depth in the Pro Git book is the reset command.

Git

Most of the reason for this, honestly, is that I never strongly understood the command beyond the handful of specific use cases that I needed it for. I knew what the command did, but not really how it was designed to work. Since then I have become more comfortable with the command, largely thanks to Mark Dominus's article re-phrasing the content of the man-page, which I always found very difficult to follow. After reading that explanation of the command, I now personally feel more comfortable using reset and enjoy trying to help others feel the same way.

This post assumes some basic understanding of how Git branching works. The Three Trees of Git The way I now like to think about reset and checkout is through the mental frame of Git being a content manager of three different trees. Git as a system manages and manipulates three trees in its normal operation. The HEAD last commit snapshot, next parent. Book. How to undo (almost) anything with Git. Viewing the Commit History. After you have created several commits, or if you have cloned a repository with an existing commit history, you’ll probably want to look back to see what has happened.

Viewing the Commit History

The most basic and powerful tool to do this is the git log command. These examples use a very simple project called “simplegit”. To get the project, run $ git clone When you run git log in this project, you should get output that looks something like this: By default, with no arguments, git log lists the commits made in that repository in reverse chronological order – that is, the most recent commits show up first. A huge number and variety of options to the git log command are available to show you exactly what you’re looking for. One of the more helpful options is -p, which shows the difference introduced in each commit. This option displays the same information but with a diff directly following each entry.

Another really useful option is --pretty. Table 2-1 lists some of the more useful options that format takes. Resolve Git merge conflicts in favor of their changes during a pull. Basic Branching and Merging. Basic Branching First, let’s say you’re working on your project and have a couple of commits already on the master branch.

Basic Branching and Merging

Figure 18. A simple commit history You’ve decided that you’re going to work on issue #53 in whatever issue-tracking system your company uses. To create a new branch and switch to it at the same time, you can run the git checkout command with the -b switch: $ git checkout -b iss53 Switched to a new branch "iss53" $ git branch iss53 $ git checkout iss53 Figure 19. You work on your website and do some commits. . $ vim index.html $ git commit -a -m 'Create new footer [issue 53]' Figure 20. Now you get the call that there is an issue with the website, and you need to fix it immediately.

However, before you do that, note that if your working directory or staging area has uncommitted changes that conflict with the branch you’re checking out, Git won’t let you switch branches. Sign In - Code School. Git. Git - GIT_DISCOVERY_ACROSS_FILESYSTEM problem when working with terminal and MacFusion. GitHub Tutorial. Git Cheat Sheet. Even with a GUI application at hand there are times when you resort to the command line.

Git Cheat Sheet

We admit we can’t memorize all important Git commands – that’s why we created a nice cheat sheet for Git that we would like to share with you. On the front you can find all important commands. On the back you can find our Version Control Best Practices that help you get the most out of version control with Git. Available in English | Deutsch | Português | العربية and for download as ZIP including various designs. Download ZIP Size: 0.9 MB, inc. 3 alternative designs & multiple languages for free …and get free email updates. Git Cheat Sheet. Understanding Git Conceptually. Introduction This is a tutorial on the Git version control system.

Understanding Git Conceptually

Git is quickly becoming one of the most popular version control systems in use. There are plenty of tutorials on Git already. How is this one different? A Story When I first started using Git, I read plenty of tutorials, as well as the user manual. After a few months, I started to understand those under-the-hood concepts. Git Reference. Git reset is probably the most confusing command written by humans, but it can be very useful once you get the hang of it.

Git Reference

There are three specific invocations of it that are generally helpful. git reset HEAD unstage files from index and reset pointer to HEAD First, you can use it to unstage something that has been accidentally staged. Let's say that you have modified two files and want to record them into two different commits. You should stage and commit one, then stage and commit the other. Ruby on rails - Pull is not possible because you have unmerged files, git stash doesn't work. Don't want to commit.