git Basic

git Basic

github shortcut

  • 模糊搜索文件:按下t
  • 快速切换分支: 按下w
  • 搜索:按下s
  • 到issue:gi
  • 到code:gc
  • 到dashboard:gd
  • 快速回复评论:选中评论然后按下r, 如果要输入表情,按下:

gitignore

touch .gitignore

然后在.gitignore文件里面写不需要上传的内容,比如

# in .gitignore

*.sh             # for all .sh files
.settings/       # for folder
!*.md            # md files should not be ignored

git branch

  • 创建分支:
git branch test1

(注意,在哪个分支下创建,就是来源于哪个分支)

  • 查看分支:
git branch 
  • 切换分支:
git checkout test1
  • 创建并且切换到新的分支(很常用):
git checkout -b test2  
  • 删除分支:
git branch -d test1
  • 强制删除分支:
git branch -D test1
  • 合并分支
git merge test2

这个是将test2分支合入当前的分支

git merge test2 --no-ff

推荐用–no-ff,会自动给merge创建一个commit,保持开发过程的完整性(不太清楚如何表述)

  • 在远程创建分支:
git push origin test2

推送到远程仓库,(假如远程仓库没有该分支)建立分支

  • 在远程删除分支:
git push origin :test2
  • 在远程创建分支并改名:
git push origin test2:t2

git log

git log 

是用来查看日志的(最上面的是最新的)

git log  --oneline 

可以更加简洁的显示日志

git show [hash code]

用来查看这次commit的详细内容

git log --all -- decorate --oneline -- graph

推荐用这个命令,可以类似GUI地显示分支之间的关系

git 回滚

Working Directory              Staging Area                Local Repository

                 git add ===>             		git commit ===>
                 <=== git reset HEAD      		<=== git reset

这部分一般是结合git log,需要先看懂git日志

  • git reset

将commit的内容拉回Staging Area:

git reset [版本号]
git reset [版本号] --soft    #不会删除相关文件
git reset [版本号] --hard    #会删除相关文件

git reset 可以向前滚,也可以向后滚

  • git revert

git revert也是用于撤销,但是与git reset相比,git revert会创建一次新的commit

git revert [commit id]

公共分支(master)使用git revert

自己的feature分支使用git reset

git 放弃修改

  • 本地修改文件,但是没有git add
git checkout -- filename   # for single file
git checkout .             # for all files and folders
  • 本地新增文件,但是没有git add
rm  -rf filename           # for single files
git clean -xdf             # for all files
git clean -xdff            # for all files and folders
  • 已经git add的文件
git reset HEAD filename    # for single files
git reset HEAD .           # for all files and folders

~/.gitconfig

gitconfig是配置文件

[filter "lfs"]
	clean = git-lfs clean -- %f
	smudge = git-lfs smudge -- %f
	process = git-lfs filter-process
	required = true
[user]
	name = Your Name
	email = Your Email
[alias]
	dog = log --all -- decorate --oneline -- graph
[http]
	proxy = http_proxy=http://127.0.0.1:1087
[https]
	proxy = https_proxy=http://127.0.0.1:1087

How to deal with conflict while merging on remote

Method 1: Merge

# update main branch
git checkout main
git pull

# merge
git checkout feature
git merge main

Method 2: Rebase

# update main branch
git checkout main
git pull

# rebase
git checkout feature
git rebase main

How to delete branches

git checkout main
git branch -d foo
git push origin --delete foo
git branch --a # check whether foo is deleted or not
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值