Git - Fixing commit mistakes | TurnKey GNU/Linux
You are here
Category: All
Git - Fixing commit mistakes
Blog Tags:
development
git
tip
Git - Fixing commit mistakes
Alon Swartz
- Mon, 2010/12/27 - 08:42 -
7 comments
I use Git. I use it a lot. I basically use it for everything I do, from code revision control to revisioning my notes, my journal, even my email archive (don't ask, it's a long story).
As with anything you do, you are bound to make mistakes. When it comes to coding and revision control, mistakes can range from bad commit messages, to buggy code, to code that shouldn't have been committed together with other code, or even at all.
Here are a couple of tips I find myself using quite often.
Correcting mistakes in the last commit
This is very easy with
git-commit --amend
, For example:
I decide I don't like the commit description I used.
git-commit --amend
# just edit the description
I want to edit buggy code I just committed to path/to/file.
editor path/to/file
git-add path/to/file
git-commit -v --amend
# note your recent changes are part of the commit
I want to remove a file I included accidentally in the last commit (e.g., because I want to commit changes to that file separately).
git-reset HEAD^1 path/to/file
# this doesn't delete your changes to path/to/file
git-commit --amend -v
git-commit -v path/to/file
# make a new commit with changes to path/to/file
Correcting mistakes in previous commits
This also uses
git-commit --amend
, but involves two extra steps:
1) git-checkout
... make your changes ...
2) git-commit --amend -v
3) git-rebase --onto HEAD
If a conflict occurs while re-applying your commits, you may have to manually resolve the conflict and then
git-rebase --continue
. See the manual page for further details.
For example, I notice I made a mistake in commit
0f0d8a27622e7bf7f008983c4b8ee23bfb9843ab
several revisions ago and I'm checked out to branch
master
To correct the commit history:
git-checkout 0f0d8a27622e7bf7f008983c4b8ee23bfb9843ab
editor path/to/file
git-add path/to/file
git-commit --amend -v
git-rebase --onto HEAD 0f0d8a27622e7bf7f008983c4b8ee23bfb9843ab master
Implications
Note that by editing your commit history you are effectively re-applying your changes, and thus creating new commits with new commit ids. For example, this means you'll have to recreate existing tags.
Comments
Side note - git included in 11.0
Alon Swartz
- Mon, 2010/12/27 - 10:27
The new TurnKey 11.0 release (soon to be announced, but the beans have already been
spilled
) includes git pre-installed as a side effect of including the awesome
etckeeper
Also, if you're in need of a code repository appliance for collaboration, take a look at
TurnKey Redmine
TurnKey Trac
, and
TurnKey Revision Control
reply
TurnKey apps / cloud & revision control
Nikos
- Wed, 2011/01/05 - 23:17
Hi Alon
Firstly let me start off by saying congratulations on being one of the forefathers of the Turnkey linux project - I am new to TKL but the more I get into it the more I see just how inovative the idea is.
We have also recently signed up for the Turnkey Hub services and feel that you guys have done a great job there too - in fact after getting my first TKL application up and running locally, I was thinking how it would sell like hot cakes if something similar could be done in the cloud and a within the same day I came across the registration form for the invitation to the service and I was delighted.
I am an IT enthusiast with a bit of a ranging background - from hardware to sys admin to web developing. Although this gives me a wide scope it has not allowed me enough time to hone my skills on in a particullar area. For the last 3 years we've been trying to get our startup web development company here in Athens Greece off the ground and I have taken a more technical role while my partner is involved with markup (html css) and design.
Needless to say we've had to work over some hurdles and currently we are working on a Joomla-VirtueMart eshop project within the the TKL Joomla application (locally for development and in the cloud as production). I have a couple of questions which I would like your insight on - again please excuse any low-level questions as my background in Linux generally is quite basic.
Is there an easy way for directly porting a local TKL Application into the Turnkey Hub?
As we have multiple coders working on our current project we would like to incorporate a code repository solution that is coupled with project management. I came across your post regarding Git being included in TK 11.0 and how you mention Redmine, Trac and Revision Control - reading up a bit I see the first two also include project management and Redmine offers gantt charts - a helpful visual aid in project management. I have a couple of questions on this topic:
Could tell me which one (out of the ones mentioned before) you feel is more beneficial? I am aiming to implement a solution that will be easy to setup both from a server perspective as well as from a user.
We already use the Joomla TKL Application where our code resides - is there an easy way to deploy Redmine, Trac into that same application instance?
Which version control system would you suggest we use if we are to be sharing between Windows and Mac - I have had some experience with Subversion in the past however I have been reading great feedback regarding Git.?
Which IDE do you think is best to go for cross-platform (to ensure uniform setup procedures when linking to the version control system) - I have worked with eclipse in the past do you feel this is a good option?
sorry for the long reply, I just would really appreciate your insight on a couple of things.
many thanks for your time
salute
nick koutakis
reply
Answer to your first question...
Jeremy Davis
- Thu, 2011/01/06 - 00:25
The best/easiest way to trasfer content between TKL instances (whether on hardware, in VMs, in the cloud, etc) is using TKLBAM. Have a read: announcement
here
and docs
here
. As for your other questions, sorry I'm not much use to you. Good luck though! :)
reply
I second Jedmeister's comment on using TKLBAM
Alon Swartz
- Thu, 2011/01/06 - 10:29
I second Jedmeister's comment on using TKLBAM. That is one of the main issues it was designed to solve - I love this quote Liraz made a while ago:
Imagine being able to develop your site on a locally running appliance (e.g., running in VirtualBox or VMWare). Then, when you're ready you can automatically migrate your appliance, with all your customizations to a cloud hosting provider of your choice.
Regarding your other questions, it depends on your needs. Trac and Redmine are competing projects. I'd recommend testing both and choosing the one you like best. If you don't need an issue tracker, the revision-control appliance might be a good fit.
I personally prefer git over all other VCS. I've been using it for years and it rocks! It is also supported on windows/mac - github has installation info
here
Regarding my preferred IDE. I don't have one, I use VIM as my exclusive editor - I find IDE's provide more distraction and annoyance than benefits (but thats me). There is a learning curve involved, but it's well worth it IMHO. It's also cross platform. BTW, I use VIM for all my editing, from code, my work journal and even my email.
BTW, Liraz wrote a nice post you might find interesting:
Using git and rsync to synchronize changes on a staging box to a live server
reply
What about adding Redmine to the Joomla TKL App?
Nikos
- Thu, 2011/01/06 - 18:37
Thanks for the tips!
Is there a way in combine TKL apps - like getting Redmine into the same instalation as TKL-Joomla?
reply
Yes and no
Jeremy Davis
- Fri, 2011/01/07 - 05:06
Yes it can be done, but TKL can't do it for you. You'll need to manually install it on top and deal with any issues that may arise. TKLBAM should easily be able to take care of backing it up (and migrating it to a new instance should you need to) but you may have to double check that it is getting all your customisations (ie that you don't put things in '
naughty
' places).
reply
I'll definately have to get on board!
Jeremy Davis
- Tue, 2010/12/28 - 00:39
Given my recent headaches after thinking that it was a good idea to delete all my old code without fully testing the end product, I think I need to have a go at git!
etckeeper sounds like a winner too, a brilliant inclusion to TKL server appliances!
reply
Pages
Add new comment
Apps
Specials
Web development
Framework
Stack
IT Infrastructure
Content management
Blogging
Ecommerce
Education
Wiki
Media
Business management
CRM
ERP
Invoicing
Messaging
Email
Forum
Chat
Issue tracking
Project management
Database
NoSQL
Developer tools
Help
Forums
Support
General
Development
Documentation
Security and News Announcements
Low-traffic newsletter: up to one email a month.
Previous issues
Categories
development
news
appliances
community
debian
release
hub
stable
iso
security
cloud
ec2
aws
proxmox
lxc
ubuntu
tkldev
tips
v16.x
drupal
More tags
Recent posts
Free up disk space
4th Aug, 2024
Python PEP 668 - working with "externally managed environment"
29th Jul, 2024
v18.0 Stable Release #6 - 10 Newly Updated ISOs, Hub Builds & Proxmox/LXC builds
17th Apr, 2024
v18.0 Stable Release #5 - 20 Updated ISOs & Hub Builds - Proxmox/LXC builds
12th Feb, 2024
v18.0 Stable Release #4 - 10 Updated ISOs & Hub Builds - Proxmox/LXC builds
5th Feb, 2024
1 of 63
next ›
Archive
August 2024
(1)
July 2024
(1)
April 2024
(1)
February 2024
(2)
November 2023
(1)
October 2023
(1)
September 2023
(1)
July 2023
(1)
April 2023
(1)
March 2023
(1)
December 2022
(1)
November 2022
(2)
Pages
Recent comments
V19?
TurnKey LXC templates are available via the Proxmox UI
Non-Aws platforms
Thanks for that!
the command for adding the
mtoolshub
Great post
US