oschina/git github使用指南
我的github仓库开通,https://git.oschina.net/zhjh256。
1、打开https://git.oschina.net/signup,没有账号的话,则新创建账号。
2、从https://github.com/git-for-windows/git/releases/download/v2.9.2.windows.1/Git-2.9.2-64-bit.exe下载并安装。
3、登录git.oschina.net,新建一个项目。
4、打开git bash,如下:
5、生成ssh公钥,如下所示:
$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/zjhua/.ssh/id_rsa):
Created directory '/c/Users/zjhua/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/zjhua/.ssh/id_rsa.
Your public key has been saved in /c/Users/zjhua/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:mOt2ztatHjrGTi8jGaekWo6EXtwy5jOl+12zqZFsVcs zjhua@WINDOWS-DV8B1PN
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| . |
| o o . |
| o S. E |
| .. ..+.+ |
|. .*++.@.+.. |
|..+B+.Bo@o=.. |
| .o+*o.X*B+. |
+----[SHA256]-----+
6、打开https://git.oschina.net/profile/sshkeys,将id_rsa.pub中的内容拷贝到相应位置,如下:
7、回到git bash,执行下列命令:
$ ssh -T git@git.oschina.net
The authenticity of host 'git.oschina.net (120.55.239.11)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'git.oschina.net,120.55.239.11' (ECDSA) to the list of known hosts.
Welcome to Git@OSC, HS专用!
出现红色代表配置成功。
或$ ssh -T git@githunb.com
8、创建git项目的本地副本。
$ git clone https://git.oschina.net/zhjh256/testgit.git
或 git clone git@github.com:hslightdb/auto_explain.git
Cloning into 'testgit'...
remote: Counting objects: 5, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 5 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (5/5), done.
Checking connectivity... done.
-------------增加项目或者修改内容---------------
9、提交本地修改
zjhua@WINDOWS-DV8B1PN MINGW64 /d/test/testgit (master)
$ git add *
zjhua@WINDOWS-DV8B1PN MINGW64 /d/test/testgit (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: pom.xml
new file: src/main/java/com/medsoft/base/utils/JsonUtils.java
new file: src/main/java/com/medsoft/dlcache/AbstractLocalCacheInitializer.java
new file: src/main/java/com/medsoft/dlcache/CacheEntry.java
new file: src/main/java/com/medsoft/dlcache/LocalCacheContainer.java
new file: src/main/java/com/medsoft/dlcache/LocalCacheService.java
new file: src/main/java/com/medsoft/dlcache/LocalCacheServiceImpl.java
new file: src/main/java/com/medsoft/dlcache/LocalCacheUpdateListener.java
new file: src/main/java/com/medsoft/dlcache/mq/LocalCacheQueueListener.java
new file: src/main/java/com/medsoft/dlcache/mq/MQProducer.java
new file: src/main/java/com/medsoft/dlcache/mq/MQProducerImpl.java
Untracked files:
(use "git add <file>..." to include in what will be committed)
.classpath
.project
zjhua@WINDOWS-DV8B1PN MINGW64 /d/test/testgit (master)
$ git commit -m "initial commit"
[master 01f1e90] initial commit
11 files changed, 998 insertions(+)
create mode 100644 pom.xml
create mode 100644 src/main/java/com/medsoft/base/utils/JsonUtils.java
create mode 100644 src/main/java/com/medsoft/dlcache/AbstractLocalCacheInitializer.java
create mode 100644 src/main/java/com/medsoft/dlcache/CacheEntry.java
create mode 100644 src/main/java/com/medsoft/dlcache/LocalCacheContainer.java
create mode 100644 src/main/java/com/medsoft/dlcache/LocalCacheService.java
create mode 100644 src/main/java/com/medsoft/dlcache/LocalCacheServiceImpl.java
create mode 100644 src/main/java/com/medsoft/dlcache/LocalCacheUpdateListener.java
create mode 100644 src/main/java/com/medsoft/dlcache/mq/LocalCacheQueueListener.java
create mode 100644 src/main/java/com/medsoft/dlcache/mq/MQProducer.java
create mode 100644 src/main/java/com/medsoft/dlcache/mq/MQProducerImpl.java
zjhua@WINDOWS-DV8B1PN MINGW64 /d/test/testgit (master)
$ git push sl HEAD
fatal: 'sl' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
zjhua@WINDOWS-DV8B1PN MINGW64 /d/test/testgit (master)
$ git push
Username for 'https://git.oschina.net': zhjh256
Counting objects: 22, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (16/16), done.
Writing objects: 100% (22/22), 11.52 KiB | 0 bytes/s, done.
Total 22 (delta 2), reused 0 (delta 0)
To https://git.oschina.net/zhjh256/testgit.git
04042d9..01f1e90 master -> master
$ git push
Username for 'https://github.com': zjhua
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/hslightdb/citus-benchmarksql.git/'
参考 https://www.cnblogs.com/sober-orange/p/git-token-push.html,获取personel key解决。
$ git push https://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@github.com/hslightdb/citus-benchmarksql.git
remote: Permission to hslightdb/citus-benchmarksql.git denied to hslightdb.
fatal: unable to access 'https://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@github.com/hslightdb/citus-benchmarksql.git/': The requested URL returned error: 403
10、打开https://git.oschina.net/zhjh256/testgit,看是不是已经提交了。。。
git默认不上传空的文件夹,如果处于项目结构完整性的考虑需要保留目录结构的话,需要在空文件夹中创建一个占位文件比如.gitkeep。
其他:
1、The file will have its original line endings in your working directory。
不影响提交,忽略即可。
2、fatal: empty ident name (for <pms@yhd-jqhadoop39.int.yihaodian.com>) not allowed
解决方法:设置user.email和user.name即可
admin@DESKTOP-LUSBR0A MINGW64 /D/ldpp/trunk/code/io-spider (master)
$ git config --global user.name "zhjh256"
admin@DESKTOP-LUSBR0A MINGW64 /D/ldpp/trunk/code/io-spider (master)
$ git config --global user.email "zhjh256@163.com"
admin@DESKTOP-LUSBR0A MINGW64 /D/ldpp/trunk/code/io-spider (master)
$ git config --list
core.symlinks=false
core.autocrlf=true
core.fscache=true
color.diff=auto
color.status=auto
color.branch=auto
color.interactive=true
help.format=html
http.sslcainfo=D:/ProgramFiles/Git/mingw64/ssl/certs/ca-bundle.crt
diff.astextplain.textconv=astextplain
rebase.autosquash=true
credential.helper=manager
user.name=e
user.email=zhjh256@163.com
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://git.oschina.net/zhjh256/io-spider.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
3、删除项目
关于git暂存区,可以参考http://www.cnblogs.com/brothertao/archive/2011/04/01/2002444.html,http://www.cnblogs.com/DreamDrive/p/4155808.html。
fatal: unable to checkout working tree
$ git clone https://gitlab.hundsun.com/LightDB1.0/lightdb-installer.git
Cloning into 'lightdb-installer'...
remote: Enumerating objects: 8873, done.
remote: Counting objects: 100% (8873/8873), done.
remote: Compressing objects: 100% (2197/2197), done.
remote: Total 8873 (delta 5475), reused 8728 (delta 5372)
Receiving objects: 100% (8873/8873), 2.14 GiB | 1.68 MiB/s, done.
Resolving deltas: 100% (5475/5475), done.
error: unable to write file bellsoft-jdk11.0.12+7-linux-aarch64-full.tar.gz
error: unable to write file bellsoft-jdk11.0.12+7-linux-amd64-full.tar.gz
error: unable to write file loongson11.1.0-jdk-11.0.13-fx-internal-loongarch64.tar.gz
error: unable to write file loongson11.1.0-jdk11.0.13_8-linux-loongarch64.tar.gz
Checking out files: 100% (413/413), done.
fatal: unable to checkout working tree
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'
检查是否没有内存、空间了?参考https://www.e-learn.cn/content/qita/660565。果然,空间不够了,如下:
zjhua@WINDOWS-MUOVTG8 MINGW64 /e/LightDB-EM-git
$ df -h
Filesystem Size Used Avail Use% Mounted on
D:/Program Files/Git 121G 118G 3.0G 98% /
C: 100G 92G 7.6G 93% /c
E: 121G 121G 7.5M 100% /e
F: 137G 135G 2.0G 99% /f
释放空间后,重新git clone即可。
git diff 返回的@@- ,+ @@的含义
其中@@ -2,5 +2,6 @@的含义:
终端所展示的文本,在新旧文件中所处的行数;-表示旧文件(版本库);+表示新文件(工作区)。
-2,5:终端所展示的文本,在旧文件中,所处于第2~5行
+2,6:终端所展示的文本,在新文件中,所处于第2~6行
git diff命令是对比两次文件修改了什么。
但如何退出呢?
![mark](http://peterboazxu.com.cn/blog/20220612/uTqGhxA48mQT.png?imageslim)
2|0方案:
在上图绿色箭头指向的冒号处: 先输入q,然后按Enter键
git补丁操作(包括冲突,合并到svn)
https://www.jc2182.com/git/git-patch.html
日常使用
add commit push区别:
git add
将自己的修改提交到缓存中
git commit
将缓存中的修改提交到本地仓库
git push
将本地仓库的修改提交到github远程仓库上
查看本地修改的文件清单
查看git所有提交历史和合并历史及详情
git分支管理
其实和svn差不多,一样的需要重量级管理。
git常用命令(足够,24 update)
https://www.php.cn/faq/464354.html
git创建补丁和应用补丁
https://www.cnblogs.com/chenfulin5/p/6210581.html
git patch报错问题
https://cloud.tencent.com/developer/ask/sof/814114