注意
切换分支后,要重启AndroidStudio ,否则代码会不同步、报错等。
You've added another git repository inside your current repository 报错
# cd 到你的根仓库目录,一般也就是你报错的当前
rm -rf .git && git rm --cache . -f
git init
git add .
git commit -m 'save'
git push -u origin -f
如何获取指定 tag 代码
git checkout tag_name
当前处于一个“detached HEAD
” 状态 ,每一个 tag 就是代码仓库中的一个快照,如果你想编辑此tag 下的代码,上面的方法就不适用了.你需要把 tag 快照对应的代码拉取到一个分支上。
例如想编辑 v1.0的tag 代码,那么可以选择如下操作
git checkout -b new_branch v1.0
git checkout -b [分支名称] [tag标签名称]
下载太慢
git config --global http.postBuffer 114288000
git如何删除本地所有未提交的更改
git checkout . && git clean -xdf
有的修改已经加入暂存区
git reset --hard
git clean -xdf
版本回退
// 查看提交Id
git log
commit 1da88c3b3e51ba72966e97908d681276952da107
// 回退至指定版本
git reset --hard 1da88c3b3e51b
HEAD is now at 1da88c3 no message
删除远程分支
git push origin :分支名称(develop)
显示隐藏文件
cd 到目标文件夹下
Shift + Command + .
其他
- 显示文件夹
defaults write com.apple.finder AppleShowAllFiles TRUE
- 隐藏文件夹
defaults write com.apple.finder AppleShowAllFiles FALSE
- 最后重启finder
killall Finder
————————————————
版权声明:本文为CSDN博主「SummerYHY」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_29679397/article/details/94397401
设置邮箱和昵称
git config --global user.name "XXX"
git config --global user.email "XXX"
关联仓库和取消仓库
1.关联
git remote add origin 远程仓库名
2.取消关联
git remote remove origin
提交本地代码和提交到远程仓库
git add .
git commit -m "first commit"
git remote add origin https://gitee.com/Steven_Hu/caller_show_history_version.git
git push -u origin master -f
克隆和查看提交记录
1.克隆
$ git clone http://git.oschina.net/yiibai/sample.git
2.查看提交记录
$ git log
1.显示整个提交历史记录,但跳过合并
$ git log --no-merges
2.显示最近两周的更改文件gitk
$ git log --since="2 weeks ago" -- gitk
3.显示最近三次的提交
git log -3
创建和删除分支
1.创建分支
git branch master_demo
2.删除分支
git branch -D 分支名
3.查看所有分支
git branch -a
4.返回
wq
pull拉取代码
$ git pull <远程主机名> <远程分支名>:<本地分支名>
$ git pull origin develop
取回origin主机的next分支,与本地的master分支合并
$ git pull origin next:master
如果远程分支(next)要与当前分支合并,则冒号后面的部分可以省略
$ git pull origin next
在本地拉取远程代码
//1.本地创建一个分支
git checkout -b 分支名
git branch
//2.拉取分支数据
git pull origin 分支名
git fetch
$ git fetch origin
$ git merge origin/next
git fetch和git pull的区别
1.git fetch:相当于是从远程获取最新版本到本地,不会自动合并。
$ git fetch origin master
$ git log -p master..origin/master
$ git merge origin/master
git pull:相当于是从远程获取最新版本并merge到本地
git pull origin master
查看不同
git diff
git diff <file> # 比较当前文件和暂存区文件差异 git diff
git diff <id1><id1><id2> # 比较两次提交之间的差异
git diff <branch1> <branch2> # 在两个分支之间比较
git diff --staged # 比较暂存区和版本库差异
git diff --cached # 比较暂存区和版本库差异
git diff --stat # 仅仅比较统计信息原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/git/git_diff.html
git checkout 切换分支, 检出,用于切换分支或恢复工作树文件
$ git checkout -b develop
1.检出索引中的所有C源文件
$ git checkout -- '*.c'
2.其他案例
$ git checkout master #//取出master版本的head。
$ git checkout tag_name #//在当前分支上 取出 tag_name 的版本
$ git checkout master file_name #//放弃当前对文件file_name的修改
$ git checkout commit_id file_name #//取文件file_name的 在commit_id是的版本。commit_id为 git commit 时的sha值。
$ git checkout -b dev/1.5.4 origin/dev/1.5.4
# 从远程dev/1.5.4分支取得到本地分支/dev/1.5.4
$ git checkout -- hello.rb
#这条命令把hello.rb从HEAD中签出.
$ git checkout .
#这条命令把 当前目录所有修改的文件 从HEAD中签出并且把它恢复成未修改时的样子.
查看状态
1.git status
$ git status
2.git status -uno
通过git status -uno
可以只列出所有已经被git管理的且被修改但没提交的文件。
6.git merge 将两个或两个以上的开发历史加入(合并)一起
1.合并分支fixes和enhancements在当前分支的顶部,使它们合并
$ git merge fixes enhancements
2.合并obsolete分支到当前分支,使用ours合并
$ git merge -s ours obsolete
3.将分支maint合并到当前分支中,但不要自动进行新的提交
$ git merge --no-commit maint
4.将分支dev合并到当前分支中,自动进行新的提交
$ git merge dev
5. 其他
git merge --abort
git merge --continue
7.git merge
本地HomePage merge develop分支
git checkout develop
git merge HomePage
git status
git push origin develop -f
8.设置和取消代理
// 设置代理
git config --global https.proxy http://127.0.0.1:1080
// 取消代理
git config --global --unset http.proxy
常见问题补充
1.fatal: Not a git repository (or any of the parent directories): .git
原因分析:一般是没有初始化git本地版本管理仓库,所以无法执行git命令
解决办法:
操作之前执行以下命令行: git init
然后执行一下git status查看状态信息
2..git文件的显示隐藏
- 显示文件夹
defaults write com.apple.finder AppleShowAllFiles TRUE
- 隐藏文件夹
defaults write com.apple.finder AppleShowAllFiles FALSE
- 最后重启finder
killall Finder