English feliratok

← Git Commits Across Multiple Files - How to Use Git and GitHub

Beágyazókód kérése
5 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. You just saw with Sarah that when you work on a project,
  2. you'll often have multiple files that you want to track together.
  3. Git calls such a collection of files a repository.
  4. When you save a version of your files in git, in other words, when you
  5. make a commit, you will save a version of every file in your repository.
  6. If you only have one file in your repository, for example game.js, you already
  7. know that git stores a version of your file each time you choose to commit.
  8. So if you committed changes at 1:00, 2:15, 6:09, 6:54 and
  9. 8:20, then it would look like this.
  10. But you might also have some other files in your repository.
  11. For example, index.html and index.css.
  12. You don't need to understand what these files are.
  13. The important thing is that all three files are connected, so
  14. they're all required for the game to function properly.
  15. Git will also track the state of these files each time you commit.
  16. A commit is a snapshot of every file in your repository at the time you
  17. choose to make the commit.
  18. So for example, this is the fourth commit in this repository.
  19. If you've only changed game.js in this fourth commit, then index.html and
  20. index.css will be identical between these two commits.
  21. On the other hand, you can change all the files in a single commit.
  22. For example, if you added a new button in the third commit,
  23. that would affect all three files.
  24. So if you did a diff between the second and
  25. the third commit, you would see the differences in all three.
  26. Let's take a look at how that looks.
  27. First, I'll do a git log, and I'll use the --stat option,
  28. which gives some statistics about which files have changed in each commit.
  29. So we can see all the same information here as before.
  30. But each commit also shows what files were affected in that commit.
  31. You can see that these most recent two commits only affected game.js.
  32. The green plus signs indicate additions, and
  33. the red minus signs indicate deletions.
  34. So you can see in this commit, some code was added and some code was deleted.
  35. The number of pluses and minuses is proportional to the size of the change.
  36. You don't need to worry about the units, but you can see that the second commit
  37. is a much bigger total change than the first commit.
  38. Now, I'll scroll down a bit to try to find a commit that affects more
  39. than one file.
  40. Here's one.
  41. You can see that this commit effected game.js, index.html, and ipad.js.
  42. Now, I'll press Q to stop viewing the git log output.
  43. And I'll go ahead and
  44. type git diff, and the two commit IDs that I want to compare.
  45. So this one, and this one.
  46. Like before, we see output in getting which file has been changed.
  47. First, game.js changed, and here's the diff for game.js.
  48. Next, we see the index.html was changed.
  49. In scrolling down, we can also see the diff for index.html.
  50. Finally, ipad.js was also changed and
  51. we can scroll down to see the changes to that file.