Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Git] 常用命令 #5

Open
vivipure opened this issue May 30, 2022 · 5 comments
Open

[Git] 常用命令 #5

vivipure opened this issue May 30, 2022 · 5 comments

Comments

@vivipure
Copy link
Owner

vivipure commented May 30, 2022

git reset <commit_id> 重置某个提交,会将对应更改进行回撤,提交一个新的提交

git reset --hard <commit_id> 重置到某个提交,该提交之后的所有更改都会丢失,不会产生新提交

git reset --soft <commit_id> 重置到某个提交,该提交后的所有更改会回到暂存区,不会产生新提交

git commit --amend 可以对已经提交的内容进行追加

git reset --hard origin/master 丢弃本地提交,重置为远端最新提交

@vivipure
Copy link
Owner Author

git branch -m <new_name> 分支改名

@vivipure
Copy link
Owner Author

tips

  1. git commit -am ''基本等同于git add . && git commit -m '', 但是不会提交新增的文件

@vivipure
Copy link
Owner Author

git remote -v 可以查看远程的URL

git remote set-url origin <url> 修改远程的地址

@vivipure
Copy link
Owner Author

fatal: Not possible to fast-forward, aborting.

合并代码时出现这个提示,说明远端和本地的提交冲突。这个时候应该取消本地的提交,暂存起来。先pull, 解决冲突

@vivipure
Copy link
Owner Author

vivipure commented Oct 20, 2022

git rebase

git rebase 可以合并几个提交为1个提交

git rebase -i HEAD~2 // 合并前两个提交
rm -rf .git/rebase-merge  // 删除未完成的rebase 
git reabse -i <commit_hash> //合并到指定请求

输入 git reabse 命令后,就会到vim 的界面。
使用pick 作为合并后的commit id, squash 合并提交到前一个提交

pick <commit_1> <msg>
squash <commit_1> <msg>

输入 wq 保存后,重新编辑提交信息,再wq即可

变基分支

从a 签出 b 之后,a更新后,可以 变基 a分支

git reabse a

这样 b合并到 a时,合并的线是一条直线

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant