`
xuanzhui
  • 浏览: 197104 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Git使用

阅读更多

1. 使用coding的托管,由于建的是私人项目,在clone项目的时候遇到403,应该是权限的问题,但是过程中并没有提示输入用户名和密码。

网上有些文章说可以通过如下方式去请求,

git clone [user@]example.com:path/to/repo.git/

实际上结果有可能是

fatal: I don't handle protocol 'xuanzhui@https'

 

最终实验发现,对于https的请求,用户是应该放在url内部的,即使这是在通过git clone,比如

git clone https://xuanzhui@git.coding.net/xuanzhui/myapp.git

 

2. 修改.gitignore之后,git还是会提交想要忽略的文件

原因是.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。那么解决方法就是先把本地缓存删除(改变成未track状态),然后再提交:

git rm -r --cached .
git add .
git commit -m "fixed untracked files"

 ref .gitignore not working

 

 3. git控制台中文文件名乱码

git config core.quotepath false

 

 4. 设置提交时显示的用户名和账户

设置全局的

git config --global user.name "John Doe" 
git config --global user.email "john@doe.org"

 

如果只是设置当前的repository

git config user.name "John Doe" 
git config user.email "john@doe.org"

 

如果只是设置当前提交的commit

git commit --author="John Doe <john@doe.org>"

 

5. 查看分支提交历史

git log

 

6. 回滚修改

git reset --hard commit_sha

 commit_sha可以通过git log查询

 

如果只是回滚到上一次提交的时候

git reset --hard HEAD~1

 

 7. 删除提交历史

使用场景,比如一不小心把密码提交到GitHub,再次修改了提交,还是可以看到历史修改

# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH

# Add all the files:
git add -A

# Commit the changes:
git commit -am "Initial commit"

# Delete the old branch:
git branch -D master

# Rename the temporary branch to master:
git branch -m master

# Finally, force update to our repository:
git push -f origin master

 参见  delete commits history with git commands

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics