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 #9

Open
chengtm opened this issue Sep 18, 2019 · 0 comments
Open

Git #9

chengtm opened this issue Sep 18, 2019 · 0 comments

Comments

@chengtm
Copy link
Owner

chengtm commented Sep 18, 2019

Git合并最新的连续的多个提交

通过rebase命令将多个commit压缩成一个:git rebase -i HEAD~[number_of_commits]
如果想要压缩最后两个commit,即将最后三个提交合并成一个,可以通过命令:
git rebase -i HEAD~3
终端执行后,会输出:

pick 16a9a47 update3 
pick a7186d8 update2
pick 7b16b28 update1
。。。

将要压缩的commit改成从pick改成squash或者s,然后保存退出。

pick 16a9a47 update3 
s a7186d8 update2
s 7b16b28 update1
。。。

通过git status,可以看到有一个提交,即将三个commit合并成一个的commit,
提交远程:git push -f
注意:这里多个commit合并是有记录的,可以看出是由多个提交合并成的。

本地代码关联远程分支

  1. git init
  2. git remote add origin [email protected]:***/my_blog.git
  3. git branch --set-upstream-to=origin/master master
    此时,可以提交代码到远程分支了,当然这种操作只适合远程分支没有代码的情况下。
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