git快速上手

1.introduce yourself to Git with your name and public email address before doing any operation

$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com

2.Initialized empty Git repository

$ git init

3.tell Git to take a snapshot of the contents of all files under the current directory (note the .)

$ git add .

4.This snapshot is now stored in a temporary staging area which Git calls the "index". 
You can permanently store the contents of the index in the repository with git commit:

$ git commit

Alternatively, instead of running git add beforehand, you can use

$ git commit -a

5.Modify some files, then add their updated contents to the index:

$ git add file1 file2 file3

6.You are now ready to commit. You can see what is about to be committed
 using git diff with the --cached option:
 
$ git diff --cached


7.You can also get a brief summary of the situation with git status:

$ git status

8.At any point you can view the history of your changes using

$ git log

You can also give commits names of your own; after running

$ git tag v2.5 1b2e1d63ff

9.A single Git repository can maintain multiple branches of development.
To create a new branch named "experimental", use

$ git branch experimental

10.you’ll get a list of all existing branches:

$ git branch

11.switch to the experimental branch

$ git switch experimental

12.Now edit a file, commit the change, and switch back to the master 
branch:

(edit file)
$ git commit -a
$ git switch master

13.You can make a different change on the master branch:

(edit file)
$ git commit -a

14.at this point the two branches have diverged, with different changes made in each.
 To merge the changes made in experimental into master, run
 
$ git merge experimental

15.If the changes don’t conflict, you’re done. If there are conflicts, 
markers will be left in the problematic files showing the conflict;

$ git diff

16.will show this. Once you’ve edited the files to resolve the conflicts,

$ git commit -a

17.will commit the result of the merge. Finally,

$ gitk

18.will show a nice graphical representation of the resulting history.
At this point you could delete the experimental branch with

$ git branch -d experimental

19.This command ensures that the changes in the experimental branch are already in the current branch.
If you develop on a branch crazy-idea, then regret it, you can always delete the branch with

$ git branch -D crazy-idea

Branches are cheap and easy, so this is a good way to try something out.

20.Any Git command that needs to know a commit can take any of these names. For example:
$ git diff v2.5 HEAD     # compare the current HEAD to v2.5
$ git branch stable v2.5 # start a new branch named "stable" based
                                     # at v2.5
$ git reset --hard HEAD^ # reset your current branch and working
                                       # directory to its state at HEAD^

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值