返回
git使用杂记 | 七日打卡
前端
2023-09-26 10:37:39
git杂记 | 七日打卡
今天稍微整理下在使用git的过程中碰到的一些问题。
出现这个问题,根据如下操作删除凭证即可解决。
git push origin master
remote: You are not authorized to push to this repository.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
删除凭证,重新输入用户名和密码。也可以通过control打开。
$ git credential-manager delete
比如要把a.html改成A.html,通常的方法是git设置大小写敏感:
git config core.ignorecase false
但是这样之后,所有文件全部大小写敏感了,如果只针对A.html这个文件呢? git允许通过隐藏文件.gitattributes来设置单个文件的大小写敏感:
*.html linguist-language=html
*.html -text
这样a.html文件的大小写是敏感的,而b.html文件大小写不敏感。
在分支合并的时候,可能会出现冲突。
$ git checkout master
Switched to branch 'master'
$ git merge feature
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.
这种时候可以用git status
来查看冲突的文件。
$ git status
On branch master
You have unmerged paths.
(fix conflicts and run "git commit")
(use "git merge --abort" to abort the merge)
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: README.md
no changes added to commit (use "git add" and/or "git commit -a")
然后使用文本编辑器打开冲突的文件,找到冲突的地方,解决冲突。
<<<<<<< HEAD
欢迎来到 GitHub!
=======
Welcome to GitHub!
>>>>>>> feature
解决冲突后,可以使用git add
命令将冲突的文件添加到暂存区,然后使用git commit
命令提交冲突的文件。
$ git add README.md
$ git commit -m "解决README.md冲突"
[master 46a1f97] 解决README.md冲突
Merge branch 'feature' into master
有时候,我们需要将本地仓库中的代码推送到远程仓库。
$ git push origin master
如果远程仓库中已经有相同的文件,那么就会产生冲突。这时候,可以使用git pull
命令将远程仓库中的代码拉取到本地仓库,然后解决冲突。
$ git pull origin master
解决冲突后,可以使用git push
命令将本地仓库中的代码推送到远程仓库。
$ git push origin master
有时候,我们需要在本地仓库中创建一个新的分支。
$ git checkout -b new-branch
在新分支中,可以使用git add
命令将文件添加到暂存区,然后使用git commit
命令提交文件。
$ git add README.md
$ git commit -m "添加README.md文件"
提交文件后,可以使用git push
命令将本地仓库中的代码推送到远程仓库。
$ git push origin new-branch
有时候,我们需要将两个分支合并到一起。
$ git checkout master
$ git merge new-branch
合并分支后,可以使用git push
命令将本地仓库中的代码推送到远程仓库。
$ git push origin master