马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
1、设置配置信息
查看配置信息:git config -l
设置用户名:git config --global user.name xxx
设置邮箱:git config --global user.email [email protected]
2、 查看状态
查看状态: git status
3、提交到暂存区和添加到版本控制
提交到 暂存区:git add
从暂存区 撤回:git rm -cached
添加到版本管理:git commit -m '注释'
添加暂存并提交到版本库(只能是已经提交过的版本):git commit -am '注释'
4、日志
查看日志 :
git log
git log --oneline
git log --pretty=oneline
5、版本回退
版本回退
回退到指定版本号的版本:git reset --hard 局部版本索引值
回退到上一个版本:git reset --hard^
回退到上n个版本:git reset --hard~n
shift + 4 到 文件末尾
shift + G 到行末尾
没有提交到版本库 回退: git reset --hard HEAD
提交到版本后回退,只能:git reset --hard 局部版本索引值
6、查看文件修改情况
在文件修改后,没有提交到暂存区前:
git diff 文件名
7、分支,合并
查看分支:git branch
创建分支:git branch 分支名
创建并切换分支:git checkout -b 分支名
合并分支 git merge 分支名
删除分支:git checkout -d 分支名
8、Gitee
远程创建仓后,出现的提示:
快速设置— 如果你知道该怎么操作,直接使用下面的地址
HTTPS
SSH
我们强烈建议所有的git仓库都有一个README, LICENSE, .gitignore文件
初始化 readme 文件
Git入门?查看 帮助 , Visual Studio / TortoiseGit / Eclipse / Xcode 下如何连接本站, 如何导入仓库
简易的命令行入门教程:
Git 全局设置:创建 git 仓库:- mkdir kh96_branch
- cd kh96_branch
- git init
- touch README.md
- git add README.md
- git commit -m "first commit"
- git remote add origin https://gitee.com/wangsong_huayu/kh96_branch.git
- git push -u origin "master"
复制代码 已有仓库?- cd existing_git_repo
- git remote add origin https://gitee.com/wangsong_huayu/kh96_branch.git
- git push -u origin "master"
复制代码 9、项目 clone,拉取,推送
从远程克隆项目: git clone 远程地址 ./
从远程拉取:git pull
推送到远程:git push -u origin master
10、 .gitignore
- # maven ignore
- target/
- *.jar
- *.war
- *.zip
- *.tar
- *.tar.gz
- # eclipse ignore
- .settings/
- .project
- .classpath
- # idea ignore
- .idea/
- *.ipr
- *.iml
- *.iws
- # temp ignore
- *.log
- *.cache
- *.diff
- *.patch
- *.tmp
- # system ignore
- .DS_Store
- Thumbs.db
- # not pull
- database.properties
- pom.xml
- src/test/
复制代码 11、修改.gitignore
.gitignore规则不生效
.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。
解决方法就是先把本地缓存删除(改变成未track状态),然后再提交:
git rm -r --cached .
git add .
git commit -m 'update .gitignore'
|