赞
踩
注:本文无特别声明默认都在Windows系统中出现的问题,在其它操作系统操作标题前会标注。
- $ git commit -m 'first commit with solidity scripts'
-
- *** Please tell me who you are.
-
- Run
-
- git config --global user.email "you@example.com"
- git config --global user.name "Your Name"
-
- to set your account's default identity.
- Omit --global to set the identity only in this repository.
- fatal: unable to auto-detect email address (got 'Tracy@DESKTOP-101.(none)')
方法一:使用命令
- git config user.name username
- git config user.email you@example.com
方法二:修改配置文件
进入项目下的 .git 目录,打开文件 config,在最前面添加一下代码
[user]
email=you@example.com
name=username
- git config --global user.name username
- git config --global user.email you@example.com
- [root@Tracy ~]# git pull origin branchName
- Username for 'https://gitee.com': xxxxx@xxx.com #请求输入用户名
- Password for 'https://xxxxx@xxx.com@gitee.com': #请求输出密码
- From https://gitee.com/talent-chain/hr-contracts
- * branch branchName -> FETCH_HEAD
- Already up-to-date.
$ git config --global credential.helper store
执行以上命令会在/root目录下生成一个.gitconfig的隐藏文件,查看一下
- [root@Tracy ~]# ls -a #查看root目录下文件(包含隐藏文件)
- . .bash_logout .bashrc .cshrc .gitconfig .pki .tcshrc
- .. .bash_profile .cache .ethash .pip .pydistutils.cfg .ssh
- [root@Tracy ~]# cat .gitconfig #查看.gitconfig文件内容
- [credential]
- helper = store
[root@Tracy ~]# vi .gitconfig
在文件头部增加下面内容(加[user]部分即可):
- [user]
- name = username
- email = email
- [credential]
- helper = store
按Esc退出编辑,输入:wq保存退出
执行git pull(或之前执行的命令)时还会提示一次输入用户名密码,之后就不再需要了。
此时,再次查看root目录下的文件,此时多了一个.git-credentials文件,有了这个文件以后就不再一个请求输入用户名密码了
- [root@Tracy ~]# ls -a
- . .bash_logout .bashrc .cshrc .gitconfig .pip .pydistutils.cfg .ssh
- .. .bash_profile .cache .ethash .git-credentials .pki .tcshrc
- $ git add .
-
- $ git reset --hard
- Deletion of directory 'contract' failed. Should I try again? (y/n) n
- HEAD is now at ece38f4 Initial commit
上面的操作导致新增文件全被删除,使用git reset --hard前请仔细思考再操作
恢复文件
- $ git fsck --full --unreachable --no-reflog
- Checking object directories: 100% (256/256), done.
- Checking objects: 100% (357/357), done.
- unreachable blob a4f0f1b2b339bf255504bb6929f83a5476c19740
- unreachable blob ba98e9463e9f44f63b3b23532070b3c78ecadb8e
- unreachable blob f7eca1298a7febf048a7d66e8453f5471355695e
- unreachable blob 45457832306f2459671dad6df2a5c4263089f19c
- # 略去许多被删除的文件blob......
通过以下指令可优雅的查看文件内容
git cat-file -p SHA #SHA为blob对象的哈希值,即上面查看到unreachable blob后面的值
- $ git cat-file -p 45457832306f2459671dad6df2a5c4263089f19c
- // SPDX-License-Identifier: MIT
- // OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
-
- pragma solidity ^0.8.7;
-
- /**
- * @dev Provides information about the current execution context, including the
- * sender of the transaction and its data. While these are generally available
- * via msg.sender and msg.data, they should not be accessed in such a direct
- * manner, since when dealing with meta-transactions the account sending and
- * paying for execution may not be the actual sender (as far as an application
- * is concerned).
- *
- * This contract is only required for intermediate, library-like contracts.
- */
- abstract contract Context {
- function _msgSender() internal view virtual returns (address) {
- return msg.sender;
- }
-
- function _msgData() internal view virtual returns (bytes calldata) {
- return msg.data;
- }
- }
可将查询的文件内容复制粘贴到文件中。
但是奇怪的是,.sol与.json文件都能查看文件内容,但是.go文件只能看到第一行,其它内容全看不到了,以下是一个.go文件的查看结果:
- $ git cat-file -p f7eca1298a7febf048a7d66e8453f5471355695e
- package tools
再查看下.go文件的大小,发现只是14,与上面第一行大小一致,这个是还原不了了,也很悲催了,大家要是有什么方法,给我留言哈
- $ git cat-file -s f7eca1298a7febf048a7d66e8453f5471355695e
- 14
$ git pull origin main
错误信息
fatal: unable to access 'https://github.com/xxxxx.git/': Failed to connect to github.com port 443: Timed out
原因未知,之前一直使用gitee,现在使用github,不知是否有关
- $ git config --global --unset http.proxy
- $ git config --global --unset https.proxy
取消代理后,再次git pull,仍然报原来的错误。
$ git config --global http.sslVerify "false"
再次git pull成功
输入2次用户密码,报错如下:
- $ git push origin main
- Logon failed, use ctrl+c to cancel basic credential prompt.
- 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/tracyzhang1998/web3js-demo.git/'
以上第2次输入密码时应该为github上设置的token,即只有有权限的用户才能做push操作的验证。
登录github,点击右上角头像 -> Settings -> Developer settings(在左侧菜单最下方)-> Personal access tokens -> click "Generate a personal access token"
再次确认密码
新建token,如下两图所示:
复制保存好这个token,关闭这个页面后token再也出不来了(如果没记住,重新生成即可)
再次git push,会输入2次用户名密码,2次用户名是一样的,第1次密码输入登录密码,第2次密码输入刚刚生成的token
下图是第1次输入的用户名密码
用户名密码输入正确,会提示:Logon failed, use ctrl+c to cancel basic credential prompt.再次输入第2次用户名密码,密码为token(第2次没有截图下来)
- Tracy@DESKTOP-101 /f/web3js/github/tracyzhang1998.github.io (master)
- $ git push origin main
- error: src refspec main does not match any
- error: failed to push some refs to 'https://github.com/tracyzhang1998/tracyzhang1998.github.io.git'
在github仓库中,分支名称为main,当本地clone仓库中分支名称默认为master,但是github上没有master,导致提交出错( add与commit时没有出错 )
重命名分支名称
- Tracy@DESKTOP-101 /f/web3js/github/tracyzhang1998.github.io (master)
- $ git branch -m master main # 重命令分支
-
- Tracy@DESKTOP-101 /f/web3js/github/tracyzhang1998.github.io (main)
- $ git push origin main # 再次push
- Enumerating objects: 8, done.
- Counting objects: 100% (8/8), done.
- Delta compression using up to 8 threads
- Compressing objects: 100% (5/5), done.
- Writing objects: 100% (7/7), 230.40 KiB | 9.60 MiB/s, done.
- Total 7 (delta 0), reused 0 (delta 0)
- To https://github.com/tracyzhang1998/tracyzhang1998.github.io.git
- e24e89b..90afdb0 main -> main
- Tracy@DESKTOP-101 /f/Golang/sl/contract
- $ git clone https://github.com/tracyzhang1998/smartcontract.git
- Cloning into 'smartcontract'...
- fatal: unable to access 'https://github.com/tracyzhang1998/smartcontract.git/': OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
服务器证书SSL没有经过第三方机构签署
$ git config --global http.sslVerify "false"
再次git clone成功。
已提交过的配置文件,之后不想再提交
$ git update-index --assume-unchanged config/*
临时在某台电脑上使用的账户下载源码,下载后想将账户删除,不保留在这台电脑上
打开控制面板 -> 用户账户 -> 凭据管理器
找到git开头的协议,查看要删除的账户,点击“删除”即可,如下图所示
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。