Git 操作小结
in Linux with 0 comment

Git 操作小结

in Linux with 0 comment

Git alias

[alias]
    co = checkout
    br = branch
    ci = commit
    st = status

新建分支

wip Work in Progress

git co -b wip-xxx-xx

Push代码

git ci -m "some word"
git push -u origin wip-xxx-xx

推送本地新分支

先确保当前已在local_branch分支,然后push

git checkout local_branch

git push origin local_branch:remote_branch

合并多个commits

设置起点

当然 origin/master 也可以改为 对应起点的commit hash值

git rebase -i origin/master
git rebase -i HEAD~3
git rebase -i 3a4226b

3a4226b 不会参与合并

选择要合并的提交

执行rebase之后,会弹出一个窗口

pick 3ca6ec3   '注释**********'
pick 1b40566   '注释*********'
pick 53f244a   '注释**********'

一共有三种状态

保留commit状态,不合并该次提交

use commit, but meld into previous commit
使用此次Commit,但会被合并到前一个Commit
like "squash", but discard this commit's log message
跟squash一样,唯一的不同时丢弃掉Commit message。
就是 git commit -m "Commit message" ,里边说的话丢弃掉。

改成这个样子

pick e7ba81d Commit-1
s 5756e15 Commit-2
s b1b8189 Commit-3

修改完成后 :wq 或者 shift + z + z 退出,进入下一个界面

# This is a combination of 3 commits.
# The first commit's message is:
Commit-1

# This is the 2nd commit message:

Commit-2

# This is the 3rd commit message:

Commit-3

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Tue Jan 5 23:27:22 2016 +0800
#
# rebase in progress; onto 5d39ff2
# You are currently editing a commit while rebasing branch 'master' on '5d39ff2'.
#
# Changes to be committed:
#   modified:   a

这里是一个编写 Commit Message 的界面, 带 # 的行会被忽略掉,其余的行就会作为新的Commit Message。将这个页面略作修改为:

Commit-1

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Tue Jan 5 23:27:22 2016 +0800
#
# rebase in progress; onto 5d39ff2
# You are currently editing a commit while rebasing branch 'master' on '5d39ff2'.
#
# Changes to be committed:
#   modified:   a

保存之后,查看log:

* 2d7b687 - (HEAD -> master) Commit-1
* 5d39ff2 - Commit-0

最后使用 git push -f 提交

命令行指令

Git 全局设置

git config --global user.name "mmmwhy"
git config --global user.email "mmmwhy@qq.com"

创建新版本库

git clone https://iii.run/mmmwhy/ssql.git
cd seq-annotation
touch README.md
git add README.md
git commit -m "add README"
git push -u origin master

已存在的文件夹或 Git 仓库

cd existing_folder
git init
git remote add origin https://iii.run/mmmwhy/sql.git
git add .
git commit -m "first commit"
git push -u origin master
Responses

From now on, bravely dream and run toward that dream.
陕ICP备17001447号