码迷,mamicode.com
首页 > 其他好文 > 详细

GitHub使用方法

时间:2014-11-11 22:53:34      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:git   工具   

        以下内容都是全英文的,对githu的使用作了详细的介绍。都是比较简单地词汇,阅读后相信你会对github的工作方式,基本操作很了解了。当然,有可能看完后你会跟我一样觉得,还不如git --help命令来得直接。

Git is a distributed version control system

To initialize a Git repository in current directory, type the following command:    git init

The current directory now has an empty repository in /.git/. The repository is a hidden directory where Git operates.

to see what the current state of our project is:    git status

if terminate prompt "untracked"? That means Git sees that file is a new file.

To tell Git to start tracking changes made to octocat.txt, we first need to add it to the staging area by using :    git add filename
after,The files listed here are in the Staging Area, and they are not in our repository yet. We could add or remove files from the stage before we store them in the repository.

checking for changes:    git status       ,to see where we stand

To store our staged changes we run the commit command with a message describing what we‘ve changed:        git commit -m “message descriptionxxxx"

We also can use wildcards if you want to add many files of the same type.:         git add ‘*.txt’

Think of Git‘s log as a journal that remembers all the changes we‘ve committed so far, in the order we committed them:         git log

created a new empty GitHub repositor, This command takes a remote name and a repository URL:    git remote add origin https://github.com/try-git/try_git.git  
git remote add xxremotename URLname

The push command tells Git where to put our commits when we‘re ready,The name of our remote is origin and the default local branch name is master. The -u tells Git to remember the parameters, so that next time we can simply run git push and Git will know what to do. Go ahead and push it!:        git push -u origin master

We can check for changes on our GitHub repository and pull down any new changes by running:        git pull origin master

 take a look at what is different from our last commit by using the git diff command.
In this case we want the diff of our most recent commit, which we can refer to using the HEAD pointer:        git diff HEAD
Using ‘git diff‘ gives you a good overview of changes you have made and lets you add files or directories one at a time and commit them separately.

Let‘s use git add to stage octofamily/octodog.txt:    git add octofamily/octodog.txt

to see the changes you just staged:        git diff —staged

unstage files by using the git reset command.:        git reset octofamily/octodog.txt

Files can be changed back to how they were at the last commit by using the command:         git checkout -- <target>.

When developers are working on a feature or bug they‘ll often create a copy (aka. branch) of their code they can make separate commits to. Then when they‘re done they can merge this branch back into their main master branch.
et‘s create a branch called clean_up:        git branch clean_up

Switching Branches--You can switch branches using the git checkout <branch> command:        git checkout clean_up

by using the git rm command which will not only remove the actual files from disk, but will also stage the removal of the files for us.

Commiting Branch Changes---git commit -m "Remove all the cats”

 Preparing to Merge------Switch to master branch :    git checkout master,     merge your changes from the clean_up branch into the master branch:    git merge clean_up

Delete branch ---You can use git branch -d <branch name> to delete a branch.:        git branch -d clean_up


Staging Area:

A place where we can group files together before we "commit" them to Git.Remember, staged files are files we have told git that are ready to be committed.
Commit A "commit" is a snapshot of our repository. This way if we ever need to look back at the changes we‘ve made (or if someone else does), we will see a nice timeline of all changes.
Wildcards:

We need quotes so that Git will receive the wildcard before our shell can interfere with it. Without quotes our shell will only execute the wildcard search within the current directory. Git will receive the list of files the shell found instead of the wildcard and it will not be able to add the files inside of the child directory.
Check all the things!

When using wildcards you want to be extra careful when doing commits. Make sure to check what files and folders are staged by using git status before you do the actual commit. This way you can be sure you‘re committing only the things you want.

More useful logs:

Use ‘git log --summary‘ to see more information for each commit. You can see where new files were added for the first time or where files were deleted. It‘s a good overview of what‘s going on in the project.

git remote:

Git doesn‘t care what you name your remotes, but it‘s typical to name your main one origin.

Cool Stuff:

When you start to get the hang of git you can do some really cool things with hooks when you push.For example, you can upload directly to a webserver whenever you push to your master remote instead of having to upload your site with an ftp client.

git stash:

Sometimes when you go to pull you may have changes you don‘t want to commit just yet. One option you have, other than commiting, is to stash the changes.Use the command ‘git stash‘ to stash your changes, and ‘git stash apply‘ to re-apply your changes after your pull.

HEAD

The HEAD is a pointer that holds your position within all your different commits. By default HEAD points to your most recent commit, so it can be used as a quick way to reference that commit without having to look up the SHA.

Branching:

Branches are what naturally happens when you want to work on multiple features at the same time. You wouldn‘t want to end up with a master branch which has Feature A half done and Feature B half done.

Rather you‘d separate the code base into two "snapshots" (branches) and work on and commit to them separately. As soon as one was ready, you might merge this branch back into the master branch and push it to the remote server.

Remove all the things!Removing one file is great and all, but what if you want to remove an entire folder? You can use the recursive option on git rm:

git rm -r folder_of_cats

This will recursively remove all folders and files from the given directory.

The ‘-a‘ option

If you happen to delete a file without using ‘git rm‘ you‘ll find that you still have to ‘git rm‘ the deleted files from the working tree. You can save this step by using the ‘-a‘ option on ‘git commit‘, which auto removes deleted files with the commit.

git commit -am "Delete stuff”

Pull Requests

If you‘re hosting your repo on GitHub, you can do something called a pull request.

A pull request allows the boss of the project to look through your changes and make comments before deciding to merge in the change. It‘s a really great feature that is used all the time for remote workers and open-source projects.

Merge Conflicts

Merge Conflicts can occur when changes are made to a file at the same time. A lot of people get really scared when a conflict happens, but fear not! They aren‘t that scary, you just need to decide which code to keep.

Force delete

What if you have been working on a feature branch and you decide you really don‘t want this feature anymore? You might decide to delete the branch since you‘re scrapping the idea. You‘ll notice that git branch -d bad_feature doesn‘t work. This is because -d won‘t let you delete something that hasn‘t been merged.

You can either add the --force (-f) option or use -D which combines -d -f together into one command.



GitHub使用方法

标签:git   工具   

原文地址:http://blog.csdn.net/codebat/article/details/41018453

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!