- Here's another article describing the same thing:
I saw that it was missing a few things, so I wrote this.
- It's okay if you don't want to use vim. This is a judgement free zone.
(ins)parsons@parson[~]$ export VISUAL=nano
To set these permanently, put them in your bash config. Alternatively, you
can set git
specific editor preferences -- Google is your friend here.
(ins)parsons@parson[~]$ git clone
https://github.com/jessfraz/dockerfiles.git
Cloning into 'dockerfiles'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 8543 (delta 2), reused 8 (delta 2), pack-reused 8532
Receiving objects: 100% (8543/8543), 72.11 MiB | 1.73 MiB/s, done.
Resolving deltas: 100% (3551/3551), done.
(ins)parsons@parson[~]$ cd dockerfiles/
- In this case we know the default branch is master -- will be useful later
(ins)parsons@parson[~/dockerfiles]$ git checkout -b feature
Switched to a new branch 'feature'
- SHOCKER: It is /probably/ master, but maybe not if your team has a different branching strategy)
$ git remote show origin
* remote origin
Fetch URL: https://github.com/jessfraz/dockerfiles.git
Push URL: https://github.com/jessfraz/dockerfiles.git
HEAD branch: master
Remote branches:
imgbot tracked
master tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
The line with the HEAD branch is the default branch.
(ins)parsons@parson[~/dockerfiles]$ rm wine/*
(ins)parsons@parson[~/dockerfiles]$ git status
On branch feature
Changes not staged for commit:
(use "git add/rm ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working
directory)
deleted: wine/Dockerfile
no changes added to commit (use "git add" and/or "git commit -a")
(ins)parsons@parson[~/dockerfiles]$ git add wine/Dockerfile
(ins)parsons@parson[~/dockerfiles]$ git commit -m "removed wine"
[feature ff616ea] removed wine
1 file changed, 17 deletions(-)
delete mode 100644 wine/Dockerfile
(ins)parsons@parson[~/dockerfiles]$ rm zsh/*
(ins)parsons@parson[~/dockerfiles]$ git add zsh/Dockerfile
(ins)parsons@parson[~/dockerfiles]$ git status
On branch feature
Changes to be committed:
(use "git reset HEAD ..." to unstage)
deleted: zsh/Dockerfile
(ins)parsons@parson[~/dockerfiles]$ git commit -m "removed zsh"
[feature 6d4278e] removed zsh
1 file changed, 13 deletions(-)
delete mode 100644 zsh/Dockerfile
- We will specify the default branch -- which we know is master -- here -- but you probably want the branch you branched your feature branch from
(ins)parsons@parson[~/dockerfiles]$ git rebase -i master
- You'll see the actual commits you're modifying here in your default VISUAL editor
pick ff616ea removed wine
pick 6d4278e removed zsh
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
I mostly only use pick
, reword
, or fixup
. You might prefer squash
to
fixup
-- the only difference being that squash
keeps your commit message.
I don't like that because I write a lot of shitty commit msgs while
debugging.
So for each commit, you can change the "pick
" part of the line to either
reword
or fixup
. Note, you obviously can't merge the first commit with
the one previous to it, so you really only can use the commands that
don't do that.
Once you've selected the commits you want to reword
or fixup
, save the
file using your editor's commands.
Now, git
will take that file and rewrite your commit history.
- So it has your re-written history too
git push -u origin feature --force
This will rewrite history on your origin (GitHub, stash, Gitlab, w.e.)