How to Undo Mistakes With Git Using the Command Line

  Рет қаралды 80,871

freeCodeCamp.org

freeCodeCamp.org

Күн бұрын

Git offers lots of different ways to undo, revert, recover and fix your mistakes. In this course, we'll look at the bad things that can happen to you - and how Git can save your neck.
✏️ This course was created by Tobias Günther from Tower. Tower creates a powerful Git desktop GUI for Mac and Windows. You can download it here: www.git-tower.com
Note: This course focuses on using Git with the command line. You do not need Tower or any other GUI software to follow along.
⭐️ Course Contents ⭐️
⌨️ (00:00) Introduction
⌨️ (00:54) Hosted by Tower
⌨️ (01:29) Git as your safety net
⌨️ (02:50) Discard all local changes in a file
⌨️ (04:28) Please be careful: discarding local changes cannot be undone!
⌨️ (05:03) Restoring deleted files
⌨️ (06:10) Discard chunks / lines in a file
⌨️ (10:22) Discarding all local changes
⌨️ (11:42) Fixing the last commit
⌨️ (14:53) What "rewriting history" means
⌨️ (15:54) Reverting a commit in the middle
⌨️ (18:48) Resetting to an old revision
⌨️ (21:48) Resetting a file to an old revision
⌨️ (23:59) The Reflog
⌨️ (24:38) Recovering deleted commits
⌨️ (27:46) Recovering deleted branches
⌨️ (31:22) Moving a commit to a new branch
⌨️ (33:55) Moving a commit to a different branch
⌨️ (35:57) Interactive Rebase: an overview of what you can do
⌨️ (37:54) Interactive Rebase: how it works in general
⌨️ (38:36) Editing old commit messages with Interactive Rebase
⌨️ (41:29) Deleting commits with Interactive Rebase
⌨️ (43:20) Squashing multiple commits into one with Interactive Rebase
⌨️ (46:00) Adding changes to an old commit with Interactive Rebase
⌨️ (51:54) Splitting/editing an old commit with Interactive Rebase
⌨️ (54:01) Reminder: don't rewrite commits that you have already shared!
⌨️ (54:38) First Aid Kit for Git: a set of short videos and a cheat sheet, free to download (www.bit.ly/git-first-aid-kit)
⭐️ Special thanks to our Champion supporters! ⭐️
🏆 Loc Do
🏆 Joseph C
🏆 DeezMaster
--
Learn to code for free and get a developer job: www.freecodecamp.org
Read hundreds of articles on programming: freecodecamp.org/news

Пікірлер: 80
@harshadpandit5483
@harshadpandit5483 Жыл бұрын
Probably the most important topic on GIT explained in the most simplest way. Awesome.
@dolusdirectu
@dolusdirectu 2 жыл бұрын
Wow, amazing tutorial. After reading the git documentation I was really confused about some topics but this lesson made it clear to me. I really appreciate it thx for the great content.
@gubazoltan99
@gubazoltan99 3 жыл бұрын
Immediately added this video to my favourites. Thanks for the clear explanation!
@moai545
@moai545 3 жыл бұрын
Thank you for giving me a very detailed and very easy-to-understand explanation!!! RESPECT!!! 🙏
@saishashank1000
@saishashank1000 3 жыл бұрын
I wished I could undo mistakes that I made in my life by using git :’)
@thengakola6217
@thengakola6217 3 жыл бұрын
F
@bishnukumarbhakat4892
@bishnukumarbhakat4892 3 жыл бұрын
Yes! you can, by following up DRY principle.
@ms711x
@ms711x 3 жыл бұрын
You can but you need admin privileges.
@Arun-bz4jr
@Arun-bz4jr 3 жыл бұрын
do it better next time, do not "commit" more mistakes :-)
@bishnukumarbhakat4892
@bishnukumarbhakat4892 3 жыл бұрын
Thank you for this drive, really it was an awesome tour to stack up the real base of "git".
@angelajholden
@angelajholden 3 жыл бұрын
This video saved me! About 2 weeks ago I deleted a commit and tried everything to could think to get it back. Discovering git reflog, then resetting or creating a new branch from that commit is exactly what I needed. And voilà, all work restored after many sleepless nights. THANK YOU SO MUCH!
@rafaelmrantunes
@rafaelmrantunes Жыл бұрын
That's a must-see for sure. Thanks for the content. Valuable af
@dlopezlo
@dlopezlo 3 жыл бұрын
thanks for the course and for making it freely available.
@ventin75
@ventin75 9 ай бұрын
Great video. I like how you presented the use cases.
@davidtang1828
@davidtang1828 3 жыл бұрын
This was awesome. Thank you! Definitely will be checking out Tower now lol.
@treequin
@treequin 11 ай бұрын
Very good tutorial! Learned quite a few things watching it. Thanks for making it!
@josearevalo3817
@josearevalo3817 3 жыл бұрын
The video is in my the top 10! Thanks! 👍🏼
@moali2990
@moali2990 Жыл бұрын
Not exaggerating, you are a gift from heaven, currently having problems with bad merges with master branch. This is helping me alot
@bouamarelouahhabi9525
@bouamarelouahhabi9525 3 жыл бұрын
I remember your voice from gitower tutorials :), thanks for the good job!
@je9625
@je9625 Ай бұрын
I have no idea why it took me three years to come across this video. It's a gem 🎉
@JeanCarlos-km3vz
@JeanCarlos-km3vz 3 жыл бұрын
Great explanation! Boom! Not panic anymore!
@dipenparmar2273
@dipenparmar2273 3 жыл бұрын
Excellent job, Great for experts as well beginners....
@sanskaarpatni9137
@sanskaarpatni9137 3 жыл бұрын
This video is so goood! Important stuff af: I had seen the video when it came out.. But yesterday when I ran into a problem I realized I should see this video again properly
@compScientizt
@compScientizt 2 жыл бұрын
You are awesome indeed. thanks alot!😍🙏 Thanks for providing such a crucial knowledge for free.
@babalolajnr
@babalolajnr 3 жыл бұрын
Nice. Been looking for this forever
@PedroMartins-mz3bl
@PedroMartins-mz3bl Ай бұрын
Awesome video. Very gut explained and very helpfull tools. Thank you
@ashaalex
@ashaalex 3 жыл бұрын
Very well explained.. Thank you very much
@privatename3621
@privatename3621 Жыл бұрын
Fantastic video. And very comprehensive. Only thing is that you never gave the CLI commands for the last exercise, "Splitting / Editing and Old Commit." I took good notes on everything else. Thanks for this post.
@mei2508
@mei2508 3 жыл бұрын
Exactly what I need!TY
@JasonHuebel
@JasonHuebel 3 жыл бұрын
Great information. Thanks for sharing.
@ozzy9846
@ozzy9846 3 жыл бұрын
Git is such an amazing tool!
@cyril7104
@cyril7104 3 жыл бұрын
The most usefull lesson, big thx!
@muhammadtalhabaig1725
@muhammadtalhabaig1725 Жыл бұрын
Thank you bro!
@Dgiulian
@Dgiulian 3 жыл бұрын
Another good tip is when we have worked on a file but want to commit only parts of it, we can use the -p option to decide which lines should and shouldn't be staged.
@captainalpha4853
@captainalpha4853 7 ай бұрын
Thanks for the tip!
@humayunakhtar2116
@humayunakhtar2116 3 жыл бұрын
Oh Man I'm so happy to learn multiple things in this video
@blasttrash
@blasttrash 3 жыл бұрын
awesome tutorial
@michaeltarassov940
@michaeltarassov940 3 жыл бұрын
Thanks a lot, it was great!
@user-sg2ft8gf9e
@user-sg2ft8gf9e 4 ай бұрын
Helpful sir thanks
@jcavelez
@jcavelez 3 жыл бұрын
Genial. Muchas gracias.
@buttnomaan
@buttnomaan 2 жыл бұрын
great video
@orafasistemas
@orafasistemas Жыл бұрын
Thank you.
@JasonHuebel
@JasonHuebel 3 жыл бұрын
11:30 That's my biggest concern, git restore doesn't ask for confirmation. While I'm OK with that in other cases, when you are discarding changes, I feel like git should err on the side of caution.
@ninjababy1997
@ninjababy1997 3 жыл бұрын
Really good video. On git restore -p enter "?" and git will show you the following: y - discard this hunk from worktree n - do not discard this hunk from worktree q - quit; do not discard this hunk or any of the remaining ones a - discard this hunk and all later hunks in the file d - do not discard this hunk or any of the later hunks in the file s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help
@mustafaaljanabi4818
@mustafaaljanabi4818 3 жыл бұрын
please I want a full course talks about HTML, CSS, and JS all of them are standard version like not html5 or css3 or something. Thanks!
@shubhamdandekar20
@shubhamdandekar20 3 жыл бұрын
Useful one.
@freecodecamp
@freecodecamp 3 жыл бұрын
If you are brand new to git, start with this video: kzbin.info/www/bejne/iHiym2ivfZyYrM0
@KrishnaKumar-ks3mj
@KrishnaKumar-ks3mj 3 ай бұрын
The one I was looking for a while, which resolves all the doubts so professionally :)
@zain.sadaqat
@zain.sadaqat 2 жыл бұрын
Nobody covered these git commands before. Thanks a lot! Can someone please tell me what are the commands for case # 17 at 54:01
@greob
@greob 3 жыл бұрын
Git Tower looks nice, but it's not available for GNU/Linux, so I'll stick with command line.
@iliyalb
@iliyalb 3 жыл бұрын
Use GitKraken
@hajarelmajid6842
@hajarelmajid6842 3 жыл бұрын
I've read it as how to do mistakes with Git and even with that I clicked never have blindly trust a channel like that!
@afrobear2310
@afrobear2310 3 жыл бұрын
never been so late !!!!
@AmitBiswastunebox
@AmitBiswastunebox Жыл бұрын
Here is the scenario, I created a branch from "develop" branch, then I created my PR against "develop". Code reviewer reviewed and Approved. Then I merged my branch (PR) with with "develop". I have have couple changes for example , commit A, B, C. so on. I just don't want changed " commit B". How to undo that form the merged PR and "develop" branch should nor have that "commit B"
@Megaheropap
@Megaheropap 3 жыл бұрын
Yes
@amitkumarjena3184
@amitkumarjena3184 3 жыл бұрын
Voila!
@harryjohn6736
@harryjohn6736 11 ай бұрын
Please provide link to your complete course.
@sakshamkshatri9649
@sakshamkshatri9649 3 жыл бұрын
Never been sooooo early!!
@mohitjoc25
@mohitjoc25 3 жыл бұрын
Make advance full course on c++ with project
@DragonStoneCreations
@DragonStoneCreations 3 жыл бұрын
❤️
@bestchoice7431
@bestchoice7431 9 ай бұрын
git restore . command do not work for deleting the untracked or unstaged files. Can we use git clean -fdx ?
@candi2Love
@candi2Love 3 жыл бұрын
How many 'CTRL Z' is allowed in Tower?
@chikaonyema2522
@chikaonyema2522 3 жыл бұрын
Wow
@imkir4n
@imkir4n 3 жыл бұрын
Im bsc cs student and its project time...could you please mention some projects with tutorials bcs many project centers approach me with expensive fees...i can't afford it...help me guys
@ashirwadsharma5462
@ashirwadsharma5462 2 жыл бұрын
git restore is not finding as a command. What would be problem??
@nordicnomad5473
@nordicnomad5473 Жыл бұрын
🎉
@OfficialOceaneMusic
@OfficialOceaneMusic 3 жыл бұрын
Question: 1)when you squash two commit into one is it ok to delete the parents of that new commit
@ankurgupta5976
@ankurgupta5976 3 жыл бұрын
This is a missing guide of my git journey.
@konstantinrebrov675
@konstantinrebrov675 3 жыл бұрын
A like for a comprehensive overview of all the different possible things one can do in git to fix your mistakes. But a dislike for using a GUI tool almost half of the time. You should have used git status and git log to find information about the commit history. And you also used the GUI tool to checkout different branches, and even do cherry-pick! I'm not necessarily against using GUI tools, but the title of your video is "How to Undo Mistakes With Git Using the Command Line ". It implies that you will not use any GUI tools, only Using the Command Line! If instead you would have used Command Line ONLY and not used the GUI tool, it would have made explaining the actual git commands better. I think that using the GUI tool is less clear about what is actually going on. It is better to use the actual Command Line to explain how git works, especially since that's the title of your video!
@RTX_valorant
@RTX_valorant 3 жыл бұрын
hi freecodecamp is it possible can we get ppt?
@thecscontent5110
@thecscontent5110 3 жыл бұрын
I also do videos about programming!😁
@vietnamneko611
@vietnamneko611 3 жыл бұрын
my parents:
@richardbajuzik2445
@richardbajuzik2445 3 жыл бұрын
Just use SmartGIT :D
@pppluronwrj
@pppluronwrj 3 жыл бұрын
delete folder then clone again
@eniluck5071
@eniluck5071 3 жыл бұрын
Use RAR instead....
@anubhavmukherjee3488
@anubhavmukherjee3488 3 жыл бұрын
Second
@user-cz7xe1xg5d
@user-cz7xe1xg5d 2 жыл бұрын
$ git restore .
@brunoribaric9683
@brunoribaric9683 3 жыл бұрын
"Using the command line" is an unnecessary addition to the title, given that a quite relevant portion of the video shows off his GUI tool.
@sujithkumar824
@sujithkumar824 3 жыл бұрын
This is why I hate people, the entire video is free, it shows everything how to do as it claims using CLI, but you still had to comment to spread negativity somehow and pointed him showing his GUI tool to make the unrelated parts faster.
@thatinstant
@thatinstant 2 ай бұрын
This video is good, but not great. What would make this video great is not shamelessly promoting that GUI app and sticking to demonstrating all scenarios with the commandline, just as the title of this video suggests. The presenter gets lazy by scenario #11 and doesn't demonstrate the commandline tasks, and only shows a summary of the commands at the end of the scenario. This is the problem with GUI apps, they make you lazy.
How to be a git expert
46:26
Floating Little Leaves of Code
Рет қаралды 140 М.
Git Branching and Merging - Detailed Tutorial
54:28
SuperSimpleDev
Рет қаралды 174 М.
Мы играли всей семьей
00:27
Даша Боровик
Рет қаралды 3 МЛН
Эта Мама Испортила Гендер-Пати 😂
00:40
Глеб Рандалайнен
Рет қаралды 8 МЛН
How to Undo a Pushed Git Commit - Reset & Revert a Git Commit After Push
12:25
Git MERGE vs REBASE: The Definitive Guide
9:39
The Modern Coder
Рет қаралды 49 М.
Git Tutorial: Fixing Common Mistakes and Undoing Bad Commits
21:31
Corey Schafer
Рет қаралды 379 М.
13 Advanced (but useful) Git Techniques and Shortcuts
8:07
Fireship
Рет қаралды 878 М.
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 910 М.
15 Lazygit Features In Under 15 Minutes
12:12
Jesse Duffield
Рет қаралды 109 М.
How GIT works under the HOOD?
16:01
Tech With Nikola
Рет қаралды 182 М.
Мы играли всей семьей
00:27
Даша Боровик
Рет қаралды 3 МЛН