Git Amend Tutorial: Rewrite Git History

  Рет қаралды 9,586

The Modern Coder

The Modern Coder

Күн бұрын

The better way to learn Git: learngit.io/
----
What is the Git amend command, and how do you use it? Git amend allows you to both rewrite the previous commit's message, and/or add files to that commit you may have forgotten. Amend is a form of editing or updating Git history. In this tutorial I'll explain how to use amend to rewrite git history (including the most used commands "git commit --amend" and "git commit --amend -m"). As always, I'll illustrate the concepts with live animations alongside the actual commands.
WRITTEN ARTICLE & REFERENCE: www.themoderncoder.com/rewrit...
GIT STARTER GUIDES: www.themoderncoder.com/git/
CHAPTERS
0:00 Intro
0:18 Git amend use-cases
0:44 Git amend: adding files to the previous commit
2:00 Important amend caveat
2:38 Use Git amend to rewrite (or update) a commit message
3:04 Altering older commits, and editing Git history
MY TECH
2020 M1 MacBook Air (I have the 512GB variant): amzn.to/3TTIBsE
AirPods Pro: amzn.to/3sRLUo5
Chair: amzn.to/3zJI9Fa
Gaming headset: amzn.to/3zwbT8i
Headphones (newer model): amzn.to/3Ub5reT
Keyboard: amzn.to/3FOOOC7
Mouse: amzn.to/3WhMFV9
Monitor: www.dell.com/en-us/work/shop/...
Monitor arm (newer model): amzn.to/3gXnlUa
Webcam: amzn.to/3zxxwp0
TECH ACCESSORIES
Laptop stand: amzn.to/3NuyqZ5
Mouse pad/mat: amzn.to/3U9QFVO
KVM switch: amzn.to/3gZmpP0
PC case: amzn.to/3Fx4Hg5
Under desk drawer: amzn.to/3WloFAo
VIDEO GEAR
Camera: amzn.to/3WkbiRe
Lens: amzn.to/3zxiTC4
Microphone: amzn.to/3SSUoWE
Main key light: amzn.to/3WhZbny
Secondary light: amzn.to/3fpRefx
Some of the links above are affiliate links which means, at no extra cost to you, I will make a small commission if you click them and make a qualifying purchase. Thanks for supporting the channel.
MUSIC CREDITS
Music from Uppbeat (free for Creators!):
uppbeat.io/t/danijel-zambo/st...
License code: IWXOQLHLMEZAFPVT
ICON CREDITS
Band Aid icon created by Konkapp - Flaticon
ABOUT ME
An experienced tech professional with experience including software engineering management, and software engineering. Formerly at Amazon for over 6 years, and currently living in NYC.
FOLLOW
Blog: www.themoderncoder.com
Twitter: / themoderncoder
#git #linux #programming #github

Пікірлер: 22
@themoderncoder
@themoderncoder Жыл бұрын
Liked this video? I have more Git videos! kzbin.info/aero/PLfU9XN7w4tFwKwh_xPSQ_X1-hROQEpHnM. Additionally, a written reference for this video is available on my blog: www.themoderncoder.com/git/
@orangekanso
@orangekanso Ай бұрын
Your teaching approach is refreshingly efficient and straightforward, guiding learners directly towards their goals. The use of animation enhances comprehension and fosters a deeper understanding of all the concepts related to Git. many thanks
@AnantaAkash.Podder
@AnantaAkash.Podder Ай бұрын
Excellent Explanation... Thank You
@uccoskun
@uccoskun 6 ай бұрын
I watched maybe 5 videos you prepared on git. I noticed they are very useful, and I appreciate the information you packed in them. They are very well structured and down to the point. On the other hand, I have a suggestion. You speak too fast, and you edit your videos to make data flow faster. It does not give time to viewers to follow what you say. When you make a statement, viewer needs some time to understand where you are focusing or digest what you say. Please slowdown and take your time so we can digest what you say. Again, thank you for these well structured videos.
@themoderncoder
@themoderncoder 5 ай бұрын
Appreciate you watching a couple of my videos, and noticing this point of improvement. I'll keep your feedback in mind - hopefully, my upcoming videos can strike a good balance between captivating and succinct.
@lengors7327
@lengors7327 9 ай бұрын
This seems like a useful feature if you're working on a project from different devices, you don't have a shared development enviroment and you wanna store your most recent modifications on remote (to use on the other device) without actually moving forward in git history. Not sure if there's a better way of accomplish the same with git, but yeah
@themoderncoder
@themoderncoder 9 ай бұрын
You could use amend for that (or commit then un-commit). But if you’re bouncing between dev environments with any kind of frequency, a lot of software engineers use file sync utilities like FreeFileSync or rsync that will work better. Especially for use cases like local development on a laptop with a cloud machine for builds.
@cedriclawrence8204
@cedriclawrence8204 8 ай бұрын
I fucks with you. thank you for always getting to the point
@themoderncoder
@themoderncoder 8 ай бұрын
I gotchu
@notfunnydidntlaugh8621
@notfunnydidntlaugh8621 6 ай бұрын
If you have projects from high school or university that you want to add to your portfolio, is it ethical to create a repository today and amend the commit date to when you completed the project? Should you provide additonal context in your github repository readmes ("eg Project completed on 5.2.17") and your github profile readme?
@themoderncoder
@themoderncoder 6 ай бұрын
In your case, if you want to put old projects on GitHub: just add a README.md file (markdown down) in the root of your directory and write some notes about when the project was originally completed. Don't worry that the commit date doesn't match when it was originally complete. Since you're not going to have commit history anyways (just one large commit will all of the code already done) amending the date on that commit, wouldn't make sense. People add old code to GitHub all the time, you your situation is not unusual.
@aogvanili1864
@aogvanili1864 7 ай бұрын
Hello good morning, please, I have a question. How or with wich software do you use to make those animations on git during the video. They are really cool and I wish to do something similar
@themoderncoder
@themoderncoder 7 ай бұрын
I create the graphics in Sketch, then I use the built-in keyframe animations that Final Cut Pro has to do the actual motion graphics part. Recently I've started incorporating Motion (Apple's motion graphics software) for more complex animations.
@aogvanili1864
@aogvanili1864 7 ай бұрын
@@themoderncoder thank you very much
@Tony.Nguyen137
@Tony.Nguyen137 Жыл бұрын
How do I push my amended commit to remote without using >push origin -f . Is there a cleaner way
@themoderncoder
@themoderncoder Жыл бұрын
No matter how you slice it you'll eventually need to "push" your local changes to remote. The thing is though, amending commits that are already in your remote repo is an anti-pattern because you could be changing commits that are already used by others on your team. In general, unless your the only developer working on the repo, don't use "push -f". I didn't research it very deeply, but here's one method to get around forcing: stackoverflow.com/a/432518
@kris.krustev
@kris.krustev Жыл бұрын
Hello, could you also make a video about git rebase?
@themoderncoder
@themoderncoder Жыл бұрын
I've got a few videos coming up on interactive rebase, and I also have an older video on rebase (kzbin.info/www/bejne/nGLan4yagaqjnas). I plan on remaking my old rebase video in a month or so
@kris.krustev
@kris.krustev Жыл бұрын
@@themoderncoder Thanks!
@sridhar-natuva
@sridhar-natuva Жыл бұрын
I have a situation can you help me with this.. 1. Commit 2 2. Merge from master 3. Commit 1 How can i make it like 1. Commit 2 2. Commit 1 3. Merge from master
@themoderncoder
@themoderncoder Жыл бұрын
You can use interactive rebase to reorder the commits (kzbin.info/www/bejne/e521q4erjtGhZq8), but if any files from merge are based on changes introduced by commit 1 it's not going to work the way you intend. If commit 1 & 2 are just local changes that haven't been committed to the shared repository yet, then you might get away with a reorder.
@sridhar-natuva
@sridhar-natuva Жыл бұрын
@@themoderncoder ok. Is there any way i can get my changes from commit 1 into untracked files and delete my original commit 1 and make a fresh commit.. is tht possible even ?
Git MERGE vs REBASE: The Definitive Guide
9:39
The Modern Coder
Рет қаралды 80 М.
Китайка и Пчелка 10 серия😂😆
00:19
KITAYKA
Рет қаралды 1,9 МЛН
Would you like a delicious big mooncake? #shorts#Mooncake #China #Chinesefood
00:30
Они убрались очень быстро!
00:40
Аришнев
Рет қаралды 2,8 МЛН
ДЕНЬ РОЖДЕНИЯ БАБУШКИ #shorts
00:19
Паша Осадчий
Рет қаралды 7 МЛН
Git STASH Tutorial
6:59
The Modern Coder
Рет қаралды 21 М.
NEOVIM GIT PRODUCTIVITY: 2024
10:22
Ashish Alex
Рет қаралды 2,2 М.
Git: изменить последний коммит (git commit --amend)
11:20
Хороший программист
Рет қаралды 16 М.
Git Tutorial For Dummies
19:25
Nick White
Рет қаралды 1 МЛН
13 Advanced (but useful) Git Techniques and Shortcuts
8:07
Fireship
Рет қаралды 888 М.
How Git Works: Explained in 4 Minutes
4:18
ByteByteGo
Рет қаралды 136 М.
Change a Git Commit in the Past with Amend and Rebase Interactive
18:05
How To Squash Your Git History Like A Pro
13:09
Colt Steele
Рет қаралды 52 М.
Git Rebase --interactive: EXPLAINED
4:54
DevOps Toolbox
Рет қаралды 6 М.
Китайка и Пчелка 10 серия😂😆
00:19
KITAYKA
Рет қаралды 1,9 МЛН