In this video we will look at some common mistakes in Git and how we can fix these mistakes. Specifically we will cover how to discard changes since your last commit, amending commits, cherry-picking hashes, resetting to a specific commit, and reverting to a specific commit.
✅ Support My Channel Through Patreon:
✅ Become a Channel Member:
✅ One-Time Contribution Through PayPal:
✅ Cryptocurrency Donations:
Bitcoin Wallet – 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet – 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet – MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot
✅ Corey’s Public Amazon Wishlist
✅ Equipment I Use and Books I Recommend:
▶️ You Can Find Me On:
My Website –
My Second Channel –
Facebook –
Twitter –
Instagram –
#Git
Nguồn: https://belahanajima.com/
Xem thêm bài viết khác: https://belahanajima.com/cong-nghe/
I made a slight mistake in the video. The -f option on git clean is for "force" and not for "files". The documentation can be found here for more info:
https://git-scm.com/docs/git-clean
You're a great teacher!
Thank youu.
To get an overview over the complete git history type "git log –all –decorate –oneline –all". You can also assign an alias, so you don't have to write the previous command out everytime. alias graph="git log -all –decorate –oneline –all". Then you can just type graph
Nice Video. Thanks.
Our AWS S3 with GitLab Integration Video https://youtu.be/acKflkrDUYE
Great tutorial on git. I highly appreciate your efforts. Many thanks
Very useful.
This is really some very very important content. Thank you. You just got one more subscriber 🙂
Why have you pushed feature branch to remote, git push -u origin FeatureBranch. At the end you are eventually deleting that branch, you merged feature branch with master and then pushed master to remote, git push origin master. Why do we have to unnecessarily create a branch in remote and then end up deleting it in the end
Amazing, user-friendly explanation!!!!
Awesome Awesome Awesome!
Just perfect.
How to get file from previos commit.
Do you have a recipe for a scenario where you need to return to an oldish feature branch – you no longer remember what changes you had introduced, so you need a quick diff between the current head and the commit that started the branch? What would be the sneakiest way to find the branch origin SHA?
Great vid! When it comes to git reset there is also a "keep" option but I have never had a clear situation to see its benefits.
Thanks for video, really helpful
how to show that "on master" with cmd in windows?
I love the way you teach. It's very easy to understand and apply everything, I do recommend your lectures to everyone cause you are super cool. Thanks man
Brilliant. Exactly what I needed
You are awesome. your teaching skills are extraordinary In 21 minutes you just cleared everything that I need to understand to get rid of all those confusions that often happened to me.
Thank you so much <3
Awesom tutorial i ever seen about git reset/reset /reset hard/revert commands
great tutorials on advanced concepts… can you also tell how to combine all commit messages into one commit message in git?
great explanation, thanks for video!
Excellent job….bro..
Just curious: Why can't we use
git checkout <branch-to-reset-pushed-commits>
git reset –soft HEAD~(number of commits to be back)
git commit -A <all what needed to be>
git push origin <branch> –force
?
instead of "revert"ing each of all commits?
In that way, we could save one commit being extra added to the branch and hence clean.
There's GOT to be a way to develop a gui for this as, looking at all this mess, I feel like I'm back to working in DOS, like??? Nah… I'll develop a gui and become as rich as Gates did with his Windoze, mwahahahaha 😈
(No mind me: cabin fever with this ugh quarantine. Stay safe and thanks again!)
Awesome video. Thanks again.
thank you
1:42 – Revert back the code that was written
3:36 – Updating the commit message alone (amend)
5:50 – Accidentally left off a file that we wanted to commit
7:38 – Move the commits to a different branch (cherry-pick)
10:26 – 3 different types of reset
13:38 – Getting rid of untracked files (git clean)
15:01 – Retrieve critical files that were lost, and you want them back (git reflog)
18:10 – Backing out changes, when other people have already checked out your changes (git revert)
how do you get your terminal to show current branch? and color code other info ? is that possible in VSCODE?
clear screen —————————————> clear
Check git version ———————————-> git –version
Add name to global variables ———————–> git config –global user.name "NAME"
Add name to global variables ———————–> git config –global user.email "EMAIL"
Check the configurations/ variables —————-> git config –list
Main git commands (Handling/staging/committing)====>
ALL THE COMMANDS ARE RAN IN GIT BASH.
KEEP IN MINE THAT THE WORD 'ORIGIN' MEANS REMOTE
REPOSITORY (name)
1 : go to the working directory
list files in the directory ——————–> ls -la
2 : Initialise repository (new) ——————–> git init (Should create a .git file in the directory
stop tracking directory ————————> rm -rf .git (Make sure to be in the directory)
3 : check untracked/ tracking files —————-> git status (red = untracked , green = tracked)
: ignore files that should not be —————-> touch .gitignore (Make sure to be in the directory)
committed/ staged (Don't put
.gitignore to the list)
4 : Check difference ——————————-> git diff
5 : Track/commit file
—————————–> git add -file name(stage a specific file) git add -A (stage all files)6 : Remove a file from staging area
—————> git reset -file name(un-stage a specific file)git reset (un-stage all files)
7 : Commit all files those are in ——————> git commit -m "-Commit name/message-" (with a message)
the staging area (git status)
: (If you run git status now, ——————–> "On branch master nothing to commit, working * directory/tree clean"
you should see something like this)
8 : Check the committs —————————–> git log
9 : Clone and use a repository
——————–> git clone –repository url--where to clone-(Clone from website)10 : Declare the origin for the git repository ——> git remote add origin "–repository url–" (Link must end with a .git)
11 : Fetch/Get data/files from the repository
——> git pull origin –branch name-===> What is a branch?
|A branch is a memory of changes that have |
|been made while the the branch is selected |
|in the prompt or anywhere else. |
12 : Make a new branch
—————————-> git branch –branch name-: There are two typed of branches, one is Local
branch, the other one is remote tracking
branch.
Local branch => Only available on your local
machine or your local
workspace.
Remote-tracking branch => The branch which
connects your local
repository to your
central repository.
13 : Delete a local branch
————————> git branch -d –branch name which you want to delete-: Delete a remote branch
———————–> git push origin –delete –branch you wanna delete-: see all the branches ————————–> git branch -a
14 : Move to a branch
—————————–> git checkout –The branch which you want to go to-: A branch is a memory of changes while the
branch is selected in the prompt.
15 : Push
—————————————–> git push -u origin –from which branch-(This command associates local branch to remote branch)16 : Merge a branch to the master branch (or any) –> git merge –branch from which you want to merge into–(Make sure you're in the branch you want to move the changes to such as master)
17 : See which branches have merged into the ——-> git branch –merged
branch you're currently on.
18 : Make the branch a remote repository (Add it
–> git push origin –local branch-into origin) or watchable by the main website
19 : Change the commit message of the last commit –> git commit ammend -m "–your updated message–" (The git history/ 40-digit code that you submit in a commit will be diff)
you did without doing another one.
20 : How to duplicate a commit from one branch to —–> Go to the branch you wanna copy from
another if you've committed in a wrong 1: git log to copy the commit code because you'll be needing it
branch. 2: After you copied the commit code,
Go to the branch you wanna copy it to
3: git cherry-pick
-commit code/history code/40-digit code-21 : How to reset
22 : Delete commits and git log history ————> 1: Copy commit code
2: git reset
-soft –paste commit code-(soft) (It will not reset the staging area hence we won't loose any work we've done): git reset
-paste commit code-(mixed) (It will reset the staging area hence we will loose the work done): git reset
-hard –paste commit code-(hard) (It will get rid of EVERYTHING including the staging area THAT IS TRACKEDBUT UNTRACKED FILES WILL STAY AS THEY WERE and
the work done)
23 : How to go back to how things were before ——> 1: git status (The file you modified will be red)
modification. 2: git diff (You'll see the difference before the last commit on that file)
3: git checkout
-file that you want to revert changes-4: git status (You will see that the file is not modified)
5: git diff (You'll not see any difference)
Hence, the file has reverted to its last version.
24 : If you wanted something to get committed ——> 1: Create the file you wanna send to the last commit (Ignore this if the file has already been created)
in the last commit, do this. 2: Put that in the staging are (The file)
3: git commit –amend
Now that a file has probably popped up on your screen, you can edit!
4: git log –stat (To see the files and changes committed on the log)
Nicely covered all git mistakes that people generally do. Thank you very much for making this video.
Awesome tut. With examples it made damn easy to understand
Lots of useful information in one place, I really enjoyed it 🙂 Thanx Corey
Cleared lot of doubts! Thanks!
Thanks for informative explanations.
i have problem that i couldn't find out it.
i have created a project by root in my UNIX system. then i make a lot of change on that. using git i give accessibility to a non root user "for example Alex" to pull and make his change on the project. but when he wanna write the change, permission denied massage is appeared and he can not write his change on the file. i checked the file permission and i saw the permission of all file and folder in project directory and sub directories change to "rw-r–x–". i wanna keep project file and folder permission on "chmod 666" and prevent change it through deployment by git. what should i do?
Outstandingly useful, Thank you.