This tutorial explains how to import a new project into git, make changes to it, and share changes with other developers. first, note that you can get documentation for a command such as "Git diff" with: $ man Git-diffimporting a new projectassume You Have A tarball project.tar.gz with your initial work. you can place it under git revision control as follows. $ tar xzf project.tar.gz $ CD project $ git init -Dbgit will replydefaulting to local storage areayou 've now initialized the working directory -- you may notice a new directory created, named ". git ". tell git that you want it to track every file under the current directory with $ git add. finally, $ git commit-AWill prompt you for a commit message, then record the current state of all the files to the repository. try modifying some files, then run $ Gi T diffto review your changes. when you're done, $ git commit-AWill again prompt your for a message describing the change, and then record the new versions of the modified files. A Note on commit messages: though not required, it's 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 descri Ption. tools that turn commits into email, for example, use the first line on the subject line and the restof the commit in the body. to add a new file, first create the file, then $ git add path/to/New/filethen commit as usual. no special command is required when removing a file; just remove it, then commit. at any point you can view the history of your changes using $ git whatchangedif you also want t O See Complete diffs at each step, use $ git whatchanged-pmanaging branchesa single git repository can maintain multiple branches of development. to create a new branch named "experimental", use $ git branch experimentalif you now run $ git branchyou'll get a list of all existing branches: experimental * masterthe "experimental" branch is the one you just created, and the "master" branch is a default bra NCH that was created for you automatically. the asterisk marks the branch you are currently on; Type $ git checkout experimentalto switch to the experimental branch. now exit a file, commit the change, and switch back to the master branch :( edit file) $ git commit-A $ git checkout mastercheck that the change you made is no longer visible, since it was made on the experimental branch and you're back on T He master branch. you can make a different change on the master branch :( edit file) $ git commit-AAT this point the two branches have diverged, with different changes made in each. to merge the changes made in the two branches, run $ git pull. experimentalif the changes don't conflict, you're done. if there are conflicts, markers will be left in the problematic files showing the conflict; $ git diffwill Show this. once you 've edited the files to resolve the conflicts, $ git commit-AWill commit the result of the merge. finally, $ gitkwill show a nice graphical representation of the resulting history. if you develop on a branch crazy-idea, then regret it, you can always delete the branch with $ git branch-d Crazy-ideabranches are cheap and easy, so this is a good way to try something out. using git F Or collaborationsuppose 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 contriory. bob begins with: $ git clone/home/Alice/Project myrepothis creates a new directory "myrepo" containing a clone of Alice's repository. the clone is on an equal footing with the original project, Posessing its own Co Py of the original project's history. bob then makes some changes and commits them :( edit files) $ git commit-A (Repeat as necessary) when he's ready, he tells Alice to pull changes from the repository at/home/Bob/myrepo. she does this with: $ CD/home/Alice/project $ git pull/home/Bob/myrepothis actually pulls changes from the branch in Bob's repository named "master ". alice cocould request a different br Anch by adding the name of the Branch to the end of the GIT pull command line. this merges Bob's changes into her repository; "Git whatchanged" will now show the new commits. if Alice has made her own changes in the meantime, then Bob's changes will be merged in, and she will need to manually fix any conflicts. A more cautious Alice might wish to examine Bob's changes before pulling them. she can d O this by creating a temporary branch just for the purpose of studying Bob's changes: $ git fetch/home/Bob/myrepo master: bob-incomingwhich fetches the changes from Bob's master branch into a new branch named bob-incoming. (unlike git pull, git fetch just fetches a copy of Bob's line of development without doing any merging ). then $ git whatchanged-P master .. bob-incomingshows a list of all the Chang Es that Bob made since he branched from Alice's master branch. after examing those changes, and possibly fixing things, Alice can pull the changes into her master branch: $ git checkout master $ git pull. bob-incomingthe last command is a pull from the "bob-Incoming" branch in Alice's own repository. later, Bob can update his repo with Alice's latest changes using $ git pullnote that he doesn't need to G Ive the path to Alice's repository; when Bob cloned Alice's repository, git stored the location of her repository in the file. git/remotes/origin, and that location is used as the default for pulls. bob may also notice a branch in his repository that he didn't create: $ git Branch * master originthe "Origin" branch, which was created automatically by "Git clone ", is a pristine copy of Alice's Master B Ranch; Bob shoshould never commit to it. if Bob later decides to work from a different host, he can still perform clones and pulls using the SSH protocol: $ git clone alice.org:/home/Alice/Project myrepoalternatively, git has a native protocol, or can use rsync or HTTP; see Git-pull for details. git can also be used in a CVS-like mode, with a central repository that varous users push changes to; see Git- Push and git for CVS users. keeping track of historygit history is represented as a series of interrelated commits. the most recent commit in the currently checked-outbranch can always be referred to as head, and the "parent" of any commit can always be referred to by appending a caret, "^ ", to the end of the name of the commit. so, for example, git diff head ^ headshows the difference between the m Ost-recently checked-in state of the tree and the previous state, andgit diff head ^ shows the difference between that previous state and the state two commits ago. Also, head ~ 5 can be used as a shorthand for head ^, and more generally head ~ N can refer to the nth previous commit. commits representing merges have more than one parent, and you can specify which parent to follow in that case; see git-rev-parse.The name of a branch can also be used to refer to the most recent commit on that branch; so you can also say things likegit diff head experimentalto see the difference between the most-recently committed tree in the current Branch and the most-recently committed tree in the experimental branch. but you may find it more useful to see the list of commits made in the experimental branch but not in the current branch, andgit whatchanged head .. experimentalwill do that, just asgit whatchanged experimental .. headwill show the list of commits made on the head but not supported ded in experimental. you can also give commits convenient names of your own: after running $ Git-tag v2.5 head ^ you can refer to head ^ by the name "v2.5 ". if you intend to share this name with other people (for example, to identify a release version), You shoshould create a "tag" object, and perhaps sign it; see Git-tag for details. you can revisit the old state of a tree, and make further modifications if you wish, using git Branch: the command $ git branch stable-release v2.5will create a new branch named "stable-release" starting from the commit which you tagged with the name v2.5.you can reset the State of any branch to an earlier commit at any time with $ git reset -- hard v2.5this will remove all later commits from this branch and reset the working tree to the state it had when the given commit was made. if this branch is the only branch containing the later commits, those later changes will be lost. don't use "Git RESET" on a publicly-visible branch that other developers pull from, as git will be confused by history that disappears in this way. from: http://www.kernel.org/pub/software/scm/git/docs/v1.2.6/tutorial.html
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.