That's a perfectly acceptable workflow, as well: $ git status Maybe you're perfectly happy with how your progress is going, but would like to switch to a temporary workspace just to try some crazy ideas out. You can do the same thing without moving in time. Now you've moved back in time, with an alternate and clean workspace in front of you, ready for whatever changes you want to make. To get your Git HEAD back down on blank tape, make a new branch: $ git checkout -b remix The original material exists, but you're branching off and doing your own version for fun. You can think of this process as trying out a different version of the same song, or creating a remix. If you look at your previous version and realise suddenly that you want to re-do everything, or at least try a different approach, then the safe way to do that is to create a new branch. By default, Git assumes you do not want to do this, so it detaches HEAD from the project and lets you work as needed without accidentally recording over something you have recorded later. When you rewind the tape in this way, if you hit the record button and go forward, you are destroying your future work. This example rewinds all the way back to your original commit: $ git log -oneline When you go back in history, you rewind your Git HEAD to a previous version of your project. This introduces the idea of branches, which are, in a way, alternate takes of the same song. The other way to check out a file is to rewind the entire Git project. Look in your Git log to verify what you did: $ git log -onelineÄ512580 restoring filename from first commitÄ®ssentially, you have rewound the tape and are taping over a bad take. $ git commit -m 'restoring filename from first commit.' (You can see your current status at any time with the git status command.) You need to add the file because it has changed, and then commit it: $ git add filename Now the older version of the file is restored into your current position. If you accidentally committed a bad version of a file and need to yank a version from even further back in time, look in your Git log to see your previous commits, and then check it out from the appropriate commit: $ git log -oneline To restore it to its former glory, use git checkout from the last known commit, which is HEAD: $ git checkout HEAD filename We all do it we get a file to a great place, we add and commit it, and then we decide that what it really needs is one last adjustment, and the file ends up completely unrecognizable. This happens when you realize you've utterly destroyed an otherwise good file. A common use is to restore a file from a previous commit, and you can also rewind your entire tape reel and go in an entirely different direction. There are two ways to use the git checkout command. Where you are in the history of your Git project, much like your location in the span of a rock album, is determined by a marker called HEAD (like the playhead of a tape recorder or record player). To move HEAD around in your own Git timeline, use the git checkout command. In today's article you will learn how to find out where you are in the history of your project, how to restore older file versions, and how to make Git branches so you can safely conduct wild experiments. Part 7: How to manage binary blobs with Git.Part 6: How to build your own Git server.Part 4: How to restore older file versions in Git.Part 3: Creating your first Git repository.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |