Pro Git Tips

1. git init

Create a new repo with exsiting project.

 

2. git diff

This command compares what's in your working directory with what's in your staging area. The result tells what changes have not been staged.

 

3. git diff --cached

Shows what you've stage that will go into your next commit. In Git v1.6 or later, you can use git diff --staged.

 

4. git comit -a -m 'comment'

skip staging area. You do not need run git add before you commit.

 

5. git rm

Reimoves the file from your working directory and you don't see it as an untracked file next time.

 

6.  git rm --cached

Remove the file from Git but keep it on your hard disk.

 

7. git mv file_a file_b

 

 8. git log -p -2

This example shows last two commit log. -p shows diff introduced in each commit.

 

9. git log --pretyy=format:"%h %s" --graph

shows branch and merge history. More options:

 

Option	Description of Output
%H	Commit hash
%h	Abbreviated commit hash
%T	Tree hash
%t	Abbreviated tree hash
%P	Parent hashes
%p	Abbreviated parent hashes
%an	Author name
%ae	Author e-mail
%ad	Author date (format respects the –date= option)
%ar	Author date, relative
%cn	Committer name
%ce	Committer email
%cd	Committer date
%cr	Committer date, relative
%s	Subject

 

10. git commit --amend

You can redo your last commit. This can be useful when you forgot to git add some files or you want to edit your commit message.

 

 

11. git reset HEAD

Change file to unstage.

 

12. git checkout -- filename

This discards your current changes. It looks like when you last committed.

 

13. git remote add shortname remote_repo

This command adds a remote repo. git remote -v shows your current remote repo.

 

14. git fetch shortname

This fetches all information you don't have in your repo but in shortname. After this, you have all refs to all branches from that remote. you can run git merge shortname/master to merge it into your master branch.

Notify git fetch pulls all new commit to your working directory but does not automatically merge it.

 

15. git pull

This fetches data and merges.

 

16. git push [remote-name] [branch-name]

E.g., "git push origin master" pushes your master branch to origin repo.

 

17. To be continued...

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值