{"id":3984,"date":"2022-12-20T17:28:37","date_gmt":"2022-12-20T20:28:37","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/gittutorial-man7\/"},"modified":"2022-12-20T17:28:37","modified_gmt":"2022-12-20T20:28:37","slug":"gittutorial-man7","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/gittutorial-man7\/","title":{"rendered":"GITTUTORIAL (man7)"},"content":{"rendered":"<h1 align=\"center\">GITTUTORIAL<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#IMPORTING A NEW PROJECT\">IMPORTING A NEW PROJECT<\/a><br \/> <a href=\"#MAKING CHANGES\">MAKING CHANGES<\/a><br \/> <a href=\"#GIT TRACKS CONTENT NOT FILES\">GIT TRACKS CONTENT NOT FILES<\/a><br \/> <a href=\"#VIEWING PROJECT HISTORY\">VIEWING PROJECT HISTORY<\/a><br \/> <a href=\"#MANAGING BRANCHES\">MANAGING BRANCHES<\/a><br \/> <a href=\"#USING GIT FOR COLLABORATION\">USING GIT FOR COLLABORATION<\/a><br \/> <a href=\"#EXPLORING HISTORY\">EXPLORING HISTORY<\/a><br \/> <a href=\"#NEXT STEPS\">NEXT STEPS<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#GIT\">GIT<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">gittutorial \u2212 A tutorial introduction to Git<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">git *<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">This tutorial explains how to import a new project into Git, make changes to it, and share changes with other developers.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">If you are instead primarily interested in using Git to fetch a project, for example, to test the latest version, you may prefer to start with the first two chapters of <b><font color=\"#0000FF\">The Git User\u2019s Manual<\/font><\/b> <small><font color=\"#000000\">[1]<\/font><\/small> <font color=\"#000000\">.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">First, note that you can get documentation for a command such as <b>git log \u2212\u2212graph<\/b> with:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ man git\u2212log<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">or:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git help log<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">With the latter, you can use the manual viewer of your choice; see <b>git-help<\/b>(1) for more information.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">It is a good idea to introduce yourself to Git with your name and public email address before doing any operation. The easiest way to do so is:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git config \u2212\u2212global user.name &#8220;Your Name Comes Here&#8221; <br \/> $ git config \u2212\u2212global user.email you@yourdomain.example.com<\/font><\/p>\n<h2>IMPORTING A NEW PROJECT <a name=\"IMPORTING A NEW PROJECT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Assume you have a tarball project.tar.gz with your initial work. You can place it under Git revision control as follows.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ tar xzf project.tar.gz <br \/> $ cd project <br \/> $ git init<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Git will reply<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">Initialized empty Git repository in .git\/<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">You\u2019ve now initialized the working directory\u2014you may notice a new directory created, named &#8220;.git&#8221;.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Next, tell Git to take a snapshot of the contents of all files under the current directory (note the <i>.<\/i>), with <i>git add<\/i>:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git add .<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This snapshot is now stored in a temporary staging area which Git calls the &#8220;index&#8221;. You can permanently store the contents of the index in the repository with <i>git commit<\/i>:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git commit<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This will prompt you for a commit message. You\u2019ve now stored the first version of your project in Git.<\/font><\/p>\n<h2>MAKING CHANGES <a name=\"MAKING CHANGES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Modify some files, then add their updated contents to the index:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git add file1 file2 file3<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">You are now ready to commit. You can see what is about to be committed using <i>git diff<\/i> with the \u2212\u2212cached option:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git diff \u2212\u2212cached<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">(Without \u2212\u2212cached, <i>git diff<\/i> will show you any changes that you\u2019ve made but not yet added to the index.) You can also get a brief summary of the situation with <i>git status<\/i>:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git status <br \/> On branch master <br \/> Changes to be committed: <br \/> Your branch is up to date with &#8216;origin\/master&#8217;. <br \/> (use &#8220;git restore \u2212\u2212staged <file>&#8230;&#8221; to unstage)<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">modified: file1 <br \/> modified: file2 <br \/> modified: file3<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If you need to make any further adjustments, do so now, and then add any newly modified content to the index. Finally, commit your changes with:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git commit<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This will again prompt you for a message describing the change, and then record a new version of the project.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Alternatively, instead of running <i>git add<\/i> beforehand, you can use<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git commit \u2212a<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">which will automatically notice any modified (but not new) files, add them to the index, and commit, all in one step.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">A note on commit messages: Though not required, it\u2019s a good idea to begin the commit message with a single short (less than 50 character) line summarizing the change, followed by a blank line and then a more thorough description. The text up to the first blank line in a commit message is treated as the commit title, and that title is used throughout Git. For example, <b>git-format-patch<\/b>(1) turns a commit into email, and it uses the title on the Subject line and the rest of the commit in the body.<\/font><\/p>\n<h2>GIT TRACKS CONTENT NOT FILES <a name=\"GIT TRACKS CONTENT NOT FILES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Many revision control systems provide an <b>add<\/b> command that tells the system to start tracking changes to a new file. Git\u2019s <b>add<\/b> command does something simpler and more powerful: <i>git add<\/i> is used both for new and newly modified files, and in both cases it takes a snapshot of the given files and stages that content in the index, ready for inclusion in the next commit.<\/font><\/p>\n<h2>VIEWING PROJECT HISTORY <a name=\"VIEWING PROJECT HISTORY\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">At any point you can view the history of your changes using<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git log<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If you also want to see complete diffs at each step, use<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git log \u2212p<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Often the overview of the change is useful to get a feel of each step<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git log \u2212\u2212stat \u2212\u2212summary<\/font><\/p>\n<h2>MANAGING BRANCHES <a name=\"MANAGING BRANCHES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">A single Git repository can maintain multiple branches of development. To create a new branch named &#8220;experimental&#8221;, use<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git branch experimental<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If you now run<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git branch<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">you\u2019ll get a list of all existing branches:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">experimental <br \/> bodies manpages.csv script_extrae_body.sh script.sh usr master<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The &#8220;experimental&#8221; branch is the one you just created, and the &#8220;master&#8221; branch is a default branch that was created for you automatically. The asterisk marks the branch you are currently on; type<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git switch experimental<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">to switch to the experimental branch. Now edit a file, commit the change, and switch back to the master branch:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">(edit file) <br \/> $ git commit \u2212a <br \/> $ git switch master<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Check that the change you made is no longer visible, since it was made on the experimental branch and you\u2019re back on the master branch.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">You can make a different change on the master branch:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">(edit file) <br \/> $ git commit \u2212a<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">at this point the two branches have diverged, with different changes made in each. To merge the changes made in experimental into master, run<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git merge experimental<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If the changes don\u2019t conflict, you\u2019re done. If there are conflicts, markers will be left in the problematic files showing the conflict;<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git diff<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">will show this. Once you\u2019ve edited the files to resolve the conflicts,<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git commit \u2212a<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">will commit the result of the merge. Finally,<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ gitk<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">will show a nice graphical representation of the resulting history.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">At this point you could delete the experimental branch with<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git branch \u2212d experimental<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This command ensures that the changes in the experimental branch are already in the current branch.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If you develop on a branch crazy\u2212idea, then regret it, you can always delete the branch with<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git branch \u2212D crazy\u2212idea<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Branches are cheap and easy, so this is a good way to try something out.<\/font><\/p>\n<h2>USING GIT FOR COLLABORATION <a name=\"USING GIT FOR COLLABORATION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Suppose that Alice has started a new project with a Git repository in \/home\/alice\/project, and that Bob, who has a home directory on the same machine, wants to contribute.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Bob begins with:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">bob$ git clone \/home\/alice\/project myrepo<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This creates a new directory &#8220;myrepo&#8221; containing a clone of Alice\u2019s repository. The clone is on an equal footing with the original project, possessing its own copy of the original project\u2019s history.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Bob then makes some changes and commits them:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">(edit files) <br \/> bob$ git commit \u2212a <br \/> (repeat as necessary)<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">When he\u2019s ready, he tells Alice to pull changes from the repository at \/home\/bob\/myrepo. She does this with:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">alice$ cd \/home\/alice\/project <br \/> alice$ git pull \/home\/bob\/myrepo master<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This merges the changes from Bob\u2019s &#8220;master&#8221; branch into Alice\u2019s current branch. If Alice has made her own changes in the meantime, then she may need to manually fix any conflicts.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The &#8220;pull&#8221; command thus performs two operations: it fetches changes from a remote branch, then merges them into the current branch.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Note that in general, Alice would want her local changes committed before initiating this &#8220;pull&#8221;. If Bob\u2019s work conflicts with what Alice did since their histories forked, Alice will use her working tree and the index to resolve conflicts, and existing local changes will interfere with the conflict resolution process (Git will still perform the fetch but will refuse to merge \u2212\u2212\u2212 Alice will have to get rid of her local changes in some way and pull again when this happens).<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Alice can peek at what Bob did without merging first, using the &#8220;fetch&#8221; command; this allows Alice to inspect what Bob did, using a special symbol &#8220;FETCH_HEAD&#8221;, in order to determine if he has anything worth pulling, like this:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">alice$ git fetch \/home\/bob\/myrepo master <br \/> alice$ git log \u2212p HEAD..FETCH_HEAD<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This operation is safe even if Alice has uncommitted local changes. The range notation &#8220;HEAD..FETCH_HEAD&#8221; means &#8220;show everything that is reachable from the FETCH_HEAD but exclude anything that is reachable from HEAD&#8221;. Alice already knows everything that leads to her current state (HEAD), and reviews what Bob has in his state (FETCH_HEAD) that she has not seen with this command.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If Alice wants to visualize what Bob did since their histories forked she can issue the following command:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ gitk HEAD..FETCH_HEAD<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This uses the same two\u2212dot range notation we saw earlier with <i>git log<\/i>.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Alice may want to view what both of them did since they forked. She can use three\u2212dot form instead of the two\u2212dot form:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ gitk HEAD&#8230;FETCH_HEAD<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This means &#8220;show everything that is reachable from either one, but exclude anything that is reachable from both of them&#8221;.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Please note that these range notation can be used with both gitk and &#8220;git log&#8221;.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">After inspecting what Bob did, if there is nothing urgent, Alice may decide to continue working without pulling from Bob. If Bob\u2019s history does have something Alice would immediately need, Alice may choose to stash her work\u2212in\u2212progress first, do a &#8220;pull&#8221;, and then finally unstash her work\u2212in\u2212progress on top of the resulting history.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">When you are working in a small closely knit group, it is not unusual to interact with the same repository over and over again. By defining <i>remote<\/i> repository shorthand, you can make it easier:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">alice$ git remote add bob \/home\/bob\/myrepo<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">With this, Alice can perform the first part of the &#8220;pull&#8221; operation alone using the <i>git fetch<\/i> command without merging them with her own branch, using:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">alice$ git fetch bob<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Unlike the longhand form, when Alice fetches from Bob using a remote repository shorthand set up with <i>git remote<\/i>, what was fetched is stored in a remote\u2212tracking branch, in this case <b>bob\/master<\/b>. So after this:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">alice$ git log \u2212p master..bob\/master<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">shows a list of all the changes that Bob made since he branched from Alice\u2019s master branch.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">After examining those changes, Alice could merge the changes into her master branch:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">alice$ git merge bob\/master<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This <b>merge<\/b> can also be done by <i>pulling from her own remote\u2212tracking branch<\/i>, like this:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">alice$ git pull . remotes\/bob\/master<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Note that git pull always merges into the current branch, regardless of what else is given on the command line.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Later, Bob can update his repo with Alice\u2019s latest changes using<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">bob$ git pull<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Note that he doesn\u2019t need to give the path to Alice\u2019s repository; when Bob cloned Alice\u2019s repository, Git stored the location of her repository in the repository configuration, and that location is used for pulls:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">bob$ git config \u2212\u2212get remote.origin.url <br \/> \/home\/alice\/project<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">(The complete configuration created by <i>git clone<\/i> is visible using <b>git config \u2212l<\/b>, and the <b>git-config<\/b>(1) man page explains the meaning of each option.)<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Git also keeps a pristine copy of Alice\u2019s master branch under the name &#8220;origin\/master&#8221;:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">bob$ git branch \u2212r <br \/> origin\/master<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If Bob later decides to work from a different host, he can still perform clones and pulls using the ssh protocol:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">bob$ git clone alice.org:\/home\/alice\/project myrepo<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Alternatively, Git has a native protocol, or can use http; see <b>git-pull<\/b>(1) for details.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Git can also be used in a CVS\u2212like mode, with a central repository that various users push changes to; see <b>git-push<\/b>(1) and <b>gitcvs-migration<\/b>(7).<\/font><\/p>\n<h2>EXPLORING HISTORY <a name=\"EXPLORING HISTORY\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Git history is represented as a series of interrelated commits. We have already seen that the <i>git log<\/i> command can list those commits. Note that first line of each git log entry also gives a name for the commit:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git log <br \/> commit c82a22c39cbc32576f64f5c6b3f24b99ea8149c7 <br \/> Author: Junio C Hamano <junkio@cox.net> <br \/> Date: Tue May 16 17:18:22 2006 \u22120700<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">merge\u2212base: Clarify the comments on post processing.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">We can give this name to <i>git show<\/i> to see the details about this commit.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git show c82a22c39cbc32576f64f5c6b3f24b99ea8149c7<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">But there are other ways to refer to commits. You can use any initial part of the name that is long enough to uniquely identify the commit:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git show c82a22c39c # the first few characters of the name are <br \/> # usually enough <br \/> $ git show HEAD # the tip of the current branch <br \/> $ git show experimental # the tip of the &#8220;experimental&#8221; branch<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Every commit usually has one &#8220;parent&#8221; commit which points to the previous state of the project:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git show HEAD^ # to see the parent of HEAD <br \/> $ git show HEAD^^ # to see the grandparent of HEAD <br \/> $ git show HEAD~4 # to see the great\u2212great grandparent of HEAD<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Note that merge commits may have more than one parent:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git show HEAD^1 # show the first parent of HEAD (same as HEAD^) <br \/> $ git show HEAD^2 # show the second parent of HEAD<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">You can also give commits names of your own; after running<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git tag v2.5 1b2e1d63ff<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">you can refer to 1b2e1d63ff by the name &#8220;v2.5&#8221;. If you intend to share this name with other people (for example, to identify a release version), you should create a &#8220;tag&#8221; object, and perhaps sign it; see <b>git-tag<\/b>(1) for details.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Any Git command that needs to know a commit can take any of these names. For example:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git diff v2.5 HEAD # compare the current HEAD to v2.5 <br \/> $ git branch stable v2.5 # start a new branch named &#8220;stable&#8221; based <br \/> # at v2.5 <br \/> $ git reset \u2212\u2212hard HEAD^ # reset your current branch and working <br \/> # directory to its state at HEAD^<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Be careful with that last command: in addition to losing any changes in the working directory, it will also remove all later commits from this branch. If this branch is the only branch containing those commits, they will be lost. Also, don\u2019t use <i>git reset<\/i> on a publicly\u2212visible branch that other developers pull from, as it will force needless merges on other developers to clean up the history. If you need to undo changes that you have pushed, use <i>git revert<\/i> instead.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The <i>git grep<\/i> command can search for strings in any version of your project, so<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git grep &#8220;hello&#8221; v2.5<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">searches for all occurrences of &#8220;hello&#8221; in v2.5.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If you leave out the commit name, <i>git grep<\/i> will search any of the files it manages in your current directory. So<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git grep &#8220;hello&#8221;<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">is a quick way to search just the files that are tracked by Git.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Many Git commands also take sets of commits, which can be specified in a number of ways. Here are some examples with <i>git log<\/i>:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git log v2.5..v2.6 # commits between v2.5 and v2.6 <br \/> $ git log v2.5.. # commits since v2.5 <br \/> $ git log \u2212\u2212since=&#8221;2 weeks ago&#8221; # commits from the last 2 weeks <br \/> $ git log v2.5.. Makefile # commits since v2.5 which modify <br \/> # Makefile<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">You can also give <i>git log<\/i> a &#8220;range&#8221; of commits where the first is not necessarily an ancestor of the second; for example, if the tips of the branches &#8220;stable&#8221; and &#8220;master&#8221; diverged from a common commit some time ago, then<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git log stable..master<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">will list commits made in the master branch but not in the stable branch, while<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git log master..stable<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">will show the list of commits made on the stable branch but not the master branch.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">The <i>git log<\/i> command has a weakness: it must present commits in a list. When the history has lines of development that diverged and then merged back together, the order in which <i>git log<\/i> presents those commits is meaningless.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Most projects with multiple contributors (such as the Linux kernel, or Git itself) have frequent merges, and <i>gitk<\/i> does a better job of visualizing their history. For example,<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ gitk \u2212\u2212since=&#8221;2 weeks ago&#8221; drivers\/<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">allows you to browse any commits from the last 2 weeks of commits that modified files under the &#8220;drivers&#8221; directory. (Note: you can adjust gitk\u2019s fonts by holding down the control key while pressing &#8220;\u2212&#8221; or &#8220;+&#8221;.)<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Finally, most commands that take filenames will optionally allow you to precede any filename by a commit, to specify a particular version of the file:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git diff v2.5:Makefile HEAD:Makefile.in<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">You can also use <i>git show<\/i> to see any such file:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">$ git show v2.5:Makefile<\/font><\/p>\n<h2>NEXT STEPS <a name=\"NEXT STEPS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">This tutorial should be enough to perform basic distributed revision control for your projects. However, to fully understand the depth and power of Git you need to understand two simple ideas on which it is based:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 The object database is the rather elegant system used to store the history of your project\u2014files, directories, and commits.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 The index file is a cache of the state of a directory tree, used to create commits, check out working directories, and hold the various trees involved in a merge.<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Part two of this tutorial explains the object database, the index file, and a few other odds and ends that you\u2019ll need to make the most of Git. You can find it at <b>gittutorial-2<\/b>(7).<\/font><\/p>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">If you don\u2019t want to continue with that right away, a few other digressions that may be interesting at this point are:<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 <b>git-format-patch<\/b>(1), <b>git-am<\/b>(1): These convert series of git commits into emailed patches, and vice versa, useful for projects such as the Linux kernel which rely heavily on emailed patches.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 <b>git-bisect<\/b>(1): When there is a regression in your project, one way to track down the bug is by searching through the history to find the exact commit that\u2019s to blame. Git bisect can help you perform a binary search for that commit. It is smart enough to perform a close\u2212to\u2212optimal search even in the case of complex non\u2212linear history with lots of merged branches.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 <b>gitworkflows<\/b>(7): Gives an overview of recommended workflows.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 <b>giteveryday<\/b>(7): Everyday Git with 20 Commands Or So.<\/font><\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><font color=\"#000000\">\u2022 <b>gitcvs-migration<\/b>(7): Git for CVS users.<\/font><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\"><b>gittutorial-2<\/b>(7), <b>gitcvs-migration<\/b>(7), <b>gitcore-tutorial<\/b>(7), <b>gitglossary<\/b>(7), <b>git-help<\/b>(1), <b>gitworkflows<\/b>(7), <b>giteveryday<\/b>(7),<\/font> <b><font color=\"#0000FF\">The Git User\u2019s Manual<\/font><\/b> <small><font color=\"#000000\">[1]<\/font><\/small><\/p>\n<h2>GIT <a name=\"GIT\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\"><font color=\"#000000\">Part of the <b>git<\/b>(1) suite<\/font><\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<table width=\"100%\" border=\"0\" rules=\"none\" frame=\"void\" cellspacing=\"0\" cellpadding=\"0\">\n<tr valign=\"top\" align=\"left\">\n<td width=\"12%\"><\/td>\n<td width=\"3%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">1.<\/font><\/p>\n<\/td>\n<td width=\"2%\"><\/td>\n<td width=\"32%\">\n<p style=\"margin-top: 1em\"><font color=\"#000000\">The Git User\u2019s Manual<\/font><\/p>\n<\/td>\n<td width=\"51%\"> <\/td>\n<\/tr>\n<\/table>\n<p style=\"margin-left:17%;\"><font color=\"#000000\">file:\/\/\/usr\/share\/doc\/git-doc\/user-manual.html<\/font><\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  gittutorial \u2212 A tutorial introduction to Git <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[971],"tags":[973,1073,972],"class_list":["post-3984","post","type-post","status-publish","format-standard","hentry","category-7-miscelanea","tag-973","tag-gittutorial","tag-man7"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=3984"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/3984\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=3984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=3984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=3984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}