博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Git学习笔记(基础)
阅读量:5944 次
发布时间:2019-06-19

本文共 4149 字,大约阅读时间需要 13 分钟。

hot3.png

To initialize a Git repository: git init
the repository status :git status
track new file: git add filename
To store our staged changes we run the commit command with a message describing what we've changed. Let's do that now by typing:  git commit -m "Add cute octocat story"
 
we can add all the new files using a wildcard with git add. Don't forget the quotes!  git add '*.txt'
browse git history: git log
remote on github : git remote add origin git@github.com:AnYuan/try_git.git
The push command tells Git where to put our commits when we're ready, and boy we're ready. So let's push our local changes to our origin repo (on GitHub).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!
We've invited other people to our github project who have pulled your changes, made their own commits, and pushed them.We can check for changes on our GitHub repository and pull down any new changes by running: git pull origin master
Let's 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
Another great use for diff is looking at changes within files that have already been staged. Remember, staged files are files we have told git that are ready to be committed.
:git add octofamily/octodog.txt
Good, now go ahead and run git diff with the --staged option to see the changes you just staged. You should see that octodog.txt was created.
: git diff --staged
Resetting the stage
So now that octodog is part of the family, octocat is all depressed. Since we love octocat more than octodog, we'll turn his frown around by removing octodog.txt.You can unstage files by using the git reset command. Go ahead and remove octofamily/octodog.txt.
:git reset octofamily/octodog.txt
Undo
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. It would be great if we could go back to how things were before octodog came around and ruined the party.Files can be changed back to how they were at the last commit by using the command: git checkout -- <target>. Go ahead and get rid of all the changes since the last commit for octocat.txt
:git checkout --octocat.txt
Branching Out
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 called clean_up, where we'll do all the work
:git branch clean_up
Switching Branches
Great! Now if you type git branch you'll see two local branches: a main branch named master and your new branch namedclean_up.You can switch branches using the git checkout <branch>command. Try it now to switch to the clean_up branch
:git checkout clean_up
Removing All the things
Ok, so you're in the clean_up branch. You can finally remove all those pesky octocats 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.
You're going to want to use a wildcard again to get all the octocats in one sweep, go ahead and run
:git rm '*.txt'

Preparing to Merge
Alrighty, the moment has come when you have to merge your changes from the clean_up branch into the master branch. Take a deep breath, it's not that scary.
We're already on the master branch, so we just need to tell Git to merge the clean_up branch into it
:git merge clean_up
Remove branch
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 the clean_up branch you don't need it anymore.
You can use git branch -d <branch name> to delete a branch. Go ahead and delete the clean_up branch now
:git branch -d clean_up
The final push
:git push

转载于:https://my.oschina.net/u/566401/blog/108916

你可能感兴趣的文章
我是怎么使用最短路径算法解决动态联动问题的
查看>>
URAL 1353 Milliard Vasya's Function DP
查看>>
速读《构建之法:现代软件工程》提问
查看>>
Android onclicklistener中使用外部类变量时为什么需要final修饰【转】
查看>>
django中聚合aggregate和annotate GROUP BY的使用方法
查看>>
TFS简介
查看>>
docker管理平台 shipyard安装
查看>>
安装django
查看>>
Bootstrap3 栅格系统-简介
查看>>
ADODB类库操作查询数据表
查看>>
【java】File的使用:将字符串写出到本地文件,大小0kb的原因
查看>>
安卓音乐播放器开发实例
查看>>
some requirement checks failed
查看>>
存储管理
查看>>
HDU-2089-不要62
查看>>
Latex学习笔记0
查看>>
css控制div强制换行
查看>>
ios 底部用定位 fixed。在软件盘出来后,页面元素被顶上去一部分,fixed定位的footer也跑到了上面去。解决方法...
查看>>
HDU1257题解
查看>>
Iterator
查看>>