Це відео відноситься до openHPI курсу Let’s Git - Versionsverwaltung und OpenSource. Бажаєте побачити більше?
An error occurred while loading the video player, or it takes a long time to initialize. You can try clearing your browser cache. Please try again later and contact the helpdesk if the problem persists.
Прокрутити до поточної позиції
- 00:00Hello and welcome.
- 00:02In this video we will look at how we make mistakes, that we may have made in our repository.
- 00:08First of all, let us consider a small scenario: We have written a guest list and would like to with the command git commit -m "added guest list" to our repository
- 00:21However, we did make a bit of a commitment in the commit message.
- 00:25How can we correct this now? There's a git commit --amend command for that in git.
- 00:34What basically happened is that git commit --as a normal commit -- does a normal commit and the new commit then replaces the old one.
- 00:43That means we can use the commit too, not just when we made a mistake in the commit message,
- 00:48but even if we forgot to staple files but they should also be included in the commit.
- 00:53If nothing other than the commit message has been changed, then the command only processes the commit message, so a text editor opens and you can edit them.
- 01:05But there is also for example the flag -m, and then we can also rewrite the commit message itself.
- 01:13And that's what we're gonna do. git commit --amend -m and then our real commit message.
- 01:21We have in mind that a new commit will be created with the changes from the last commit, but the new commit message and the new one will replace the old commit.
- 01:33Right. So now we know, how we can correct erroneous commits.
- 01:38Now let's go a step further and look at each other, how we can unstay stale files.
- 01:45We also have a scenario here, which is that we have altered two lists.
- 01:49On the one hand we have the player list and the material list, we'd both like our changes to the lists but in two separate commits.
- 01:59But now we have entered git add *, which means all unstaged files are now packed into the staging area.
- 02:08And accordingly, if we were to commit now, we'd both commit changes.
- 02:12Now, how can we possibly have one of our two lists from our staging area?
- 02:17Well, we have already learned that Git helps us quite often, how we can do things.
- 02:23So we also enter git status here again.
- 02:26Here is a small disclaimer, depending on the version of Git you have installed, these messages can vary at git status.
- 02:34However, all the orders we explain to you here should still work in the future.
- 02:41So if we look at it, we see that Git tells us with git reset HEAD and then the filename, we can unstay files again.
- 02:50We'll see down at Modified, that both lists are currently in the staging area.
- 02:55That is, if we now enter git reset HEAD materialliste.txt, the material list should be removed from our staging area.
- 03:05We can see that down there too, Git gives us as output: unstaged changes after reset materialliste.txt, which means that the material list is now marked as unstaged again.
- 03:18So if we now enter git status again, we see "changes to be committed" above, our game list.
- 03:25That would mean that if we commit now, only our games list will be committed and below, "changes not staged for commit", we have our material list.
- 03:34Let's just deal with this for now, how we want to discard any changes we have made.
- 03:42And for this we will now focus on the point down here, "changes not staged for commit", because it also says at git status what you have to do for it, the item git checkout --file to discard changes in working directory.
- 03:58So this is obviously exactly what we want, we want the changes, that we made in our employment records.
- 04:05We then do this on the material list, git checkout --materialliste.txt, and then we use git status to see what the state of our repository is.
- 04:21And there we see then, the lower point, which we had seen before, is gone, and the only thing left to modify is the roster, and it's in the staging area right now.
- 04:31And I have to warn you a little bit: git checkout file name is very risky.
- 04:40All the local changes you made will disappear forever, and they can't be restored.
- 04:46But in Git, everything that was committed can be restored, even if it's sometimes quite difficult.
- 04:55But since you checkout at git -- and then the file name, for example materialliste.txt, that has not committed the changes, they cannot be restored afterwards.
- 05:06Which brings us now to our cheat sheet, and we see we've learned three new commands,
- 05:14git reset HEAD and then the file name, so we can remove files from the staging area,
- 05:22We can discard changes to files with git checkout -- and then the file name.
- 05:27And we can help change the last commit with git commit --amend.
- 05:32That was it for this video, I'm glad you guys were there.
- 05:36In that sense, Let's Git
Щоб увімкнути запис, виберіть мову в меню налаштувань відео.