git init 初始化
git status 告诉你在哪个分支,Initial commit,以及文件夹里可添加的文件
可以常用 git status, 它告诉你:分支,Initial commit,已添加文件,可添加文件
Notice how Git sayschanges to be committed? The files listed here are in theStaging 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.
本地有相同的 文件或者文件夹
先rm了
MacBook-Air:github huangyong$ git pull origin master
Enter passphrase for key '/Users/huangyong/.ssh/id_rsa':
From github.com:Inspiring26/baiduPic
* branch master -> FETCH_HEAD
error: The following untracked working tree files would be overwritten by merge:
getpic/Count.java
getpic/Downloadpic.java
getpic/Spider.java
getpic/Test.java
Please move or remove them before you merge.
Aborting
git pull origin master
MacBook-Air:github huangyong$ git pull origin master
Enter passphrase for key '/Users/huangyong/.ssh/id_rsa':
From github.com:Inspiring26/baiduPic
* branch master -> FETCH_HEAD
文件全下载下来了,和git clone功能有的一拼
把要更新的文件替换了
git commit -m ''
然后
git push -u origin master
到此为止就把更新的文件更新上去了。
git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean
当使用通配符(wildcards)时,会把子文件夹的相关的文件也添加进去的。
git log 看我们所有的提交
The push command tells Git where to put our commits when we're ready,
The name of our remote isoriginand the default local branch name is master.
远程的叫origin,本地的叫master
he-utells Git to remember the parameters, so that next time we can simply rungit pushand Git will know what to do.
-u 是为了让git记住push的参数,下次可以直接git push,参数大概就是远程的origin对应本地的master
By default HEAD points to your most recent commit
默认地,HEAD指向最近的提交
we want the diff of our most recent commit, which we can refer to using the HEAD pointer
要看最近的版本之间的不同,我们可以用HEAD 指针
staged files are files we have told git that are ready to be committed.
stage 阶段,staged files 标示已经存储、或者说已经提交的文件。
这些文件是可以cimmit的
Let's use git add to stage octofamily/octodog.txt
我们用git add 来stage文件,那cache是什么鬼?
run git diff with the--staged option to see the changes you just staged.
You can unstage files by using the git reset command.
git reset octofamily/octodog.txt
git reset did a great job of unstaging octodog.txt, but you'll notice that he's still there. He's just not staged anymore
Files can be changed back to how they were at the last commit by using the command:git checkout -- target
你可以使用git checkout file,把文件滚回到最近的版本
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.
We want to remove all these pesky octocats, so let's create a branch calledclean_up, where we'll do all the work:
git branch clean_up
使用git branch 分支名 就可以创建新的分支
使用git branch 可以查看所有分支
$ git branch
clean_up�
* �master�
Use 'git checkout' to switch to the 'clean_up' branch
使用git checkout 分支名可以切换分支
git rm 是一个应该常用,而我用的太少的命令
Great, you're almost finished with the cat... er the bug fix, you just need to switch back to themasterbranch so you can copy (ormerge) your changes from theclean_upbranch back into the master branch.
在新的分支修改bug,修改完后,切换到原来的分支,然后把改变应用到新分支上。
在这之前不需要push 只需要更改之后commit就可以 切换过来了
我以后要按照这种创建新分支的方法,去修改、更新程序,然后在切过来,然后merge
merge your changes from theclean_upbranch into the master branch.
We're already on themasterbranch, so we just need to tell Git to merge theclean_upbranch into it:
git merge clean_up
Congratulations! You just accomplished your first successful bugfix and merge. All that's left to do is clean up after yourself. Since you're done with theclean_upbranch you don't need it anymore.
You can usegit branch -d 分支名 to delete a branch.
Here we are, at the last step. I'm proud that you've made it this far, and it's been great learning Git with you. All that's left for you to do now is to push everything you've been working on to your remote repository, and you're done!
git push