git使用问题(备忘帖)

1)删除提交记录
git reset --hard "commit ID"
e.g git reset --hard "0604b21f7f6e0c7abb8d73d56bfdb6e2d11836cd"
git push origin HEAD --force
前提是对操作的repo目录,有force push权限。
这样会彻底从commit history删除,而且对文件所做的修改也删除。
revert
只是回滚对文件所做的修改,但是git operation都会在commit history里删除。

2)git stash用法
git stash save "work in progress for too feature" #
保存当前工作进程,并命名加以区分
git diff HEAD #
查看当前工作区和本地repo的区别,并无区别才是对的,因为工作区已经被暂存
git stash list #
查看当前所有stash
git stash apply --index "stash@{1}"
git diff HEAD #
查看当前工作区和本地repo的区别,有区别才是对的,应用了工作区的修改

3)按照下列步骤创建repo失败00

步骤:

pc_user_name@CN00207328 MINGW64 /c/repo/test_repo (master)

echo "#This is test_repo" >> README.md

git init

git add README.md

git commit -m "first commit"

git remote add origin https://github.com/GITHUBSIGNUM/test_repo.git

git push -u origin master

pc_user_name@CN00207328 MINGW64 /c/repo/test_repo (master)

错误信息:

hunjng@CN00207328 MINGW64 /c/repo/test_repo (master)

$ git remote add origin https://github.com/GITHUBSIGNUM/test_repo.git

pc_user_name@CN00207328 MINGW64 /c/repo/test_repo (master)

$ git push -u origin master

remote: Repository not found.

fatal: repository 'https://github.com/GITHUBSIGNUM/test_repo.git/' not found

原因:need to create the repository on GitHub first.It can't find the repository because it doesn't exist yet!

http://stackoverflow.com/questions/10922028/github-error-repository-not-found-fatal-the-remote-end-hung-up-unexpectedly

4)提交已经修改的注释
git commit -amend
#
修改前次提交的注释 --amend amend previous commit
https://help.github.com/articles/changing-a-commit-message/

5)如何只更新一个文件
git fetch
git checkout origin/master -- training-basic/src/main/somefile.java

6)others

Maven

http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

转载于:https://www.cnblogs.com/gracejiang/p/6601673.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值