git

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,189评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,577评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,857评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,703评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,705评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,620评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,995评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,656评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,898评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,639评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,720评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,395评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,982评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,953评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,195评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,907评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,472评论 2 342

推荐阅读更多精彩内容