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

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容