推到此分支:
git add .
git commit -m"xxx"
git push
切换分支:git checkout xxx(分支名)
添加新分支但是留在当前分支
git branch <new name>
添加并切换到新分支:
git checkout -b <new name>
忽视哪些文件不push上去:
创建.gitignore文件
拉取分支:
git pull
拉取主分支:
git pull origin master
查看历史提交记录
git log
结果:
PS C:\Users\heziyi6\Desktop\automind-backend> git log commit
1a7bcbc5397488d488829e7ff190233d724efb29 (HEAD -> feature-2,
origin/feature-2) Author: heziyi 1417243391@qq.com Date: Sat Mar
12 11:28:32 2022 +0800
commit 7ac690cafb5dfb6885b6030014cedb28aa1da3f1 Merge: 985a547 4dc81e2
Author: heziyi 1417243391@qq.com Date: Sat Mar 12 11:16:35 2022
+0800
回退到某个分支:
git reset --hard 1a7bcbc5397488d488829e7ff190233d724efb29
列出本地已经存在的分支:
git branch
列出远程分支
git branch -r
列出本地分支和远程分支
git branch -a
例子:
PS C:\Users\heziyi6\Desktop\automind-backend> git branch -a
- feature-1 master remotes/origin/HEAD -> origin/master remotes/origin/develop remotes/origin/feature-1
remotes/origin/feature-2 remotes/origin/feature-export_word
remotes/origin/master …skipping…- feature-1 master remotes/origin/HEAD -> origin/master remotes/origin/develop remotes/origin/feature-1
remotes/origin/feature-2 remotes/origin/feature-export_word
remotes/origin/master
查看现有远程仓库的地址url
git remote -v
gitignore文件更改后不生效怎么办:
新增的忽略文件没有生效,是因为git是有缓存的,无法给缓存中的内容制定规则。我们需要清除缓存再重新提交。
git rm -r --cached .
git add .
拉取远程某个分支:
git pull origin feature:feature