Reputation: 57
Git newb here. I want to use git for version control of writing, not codes.
If you want to view an earlier version in either a branch or a master, how do you open the file and view it? Eg. if you're on writing draft 2 but want to view some of the things you wrote and deleted in writing draft 1, how would you get draft 1 to open in, say, MS Word? And then return to draft 2.
Revert appears to make later commits invisible under "git log", and reset justs erases everything after the commit that you select.
Thanks in advance!
Upvotes: 0
Views: 236
Reputation: 21998
Detach HEAD
To inspect the state of your application at some given commit, the default would be to just
git checkout <commitHash>
It will detach HEAD
, and your working tree will be made to match that commit's tree.
You'll be able to come back to any branch with another checkout
.
Temporary branch
Of course, you could very well prefer to take advantage of git's light branching architecture, and create a branch at the point you want to inspect, it will be as quick to delete it as it was to create it.
# creation
git checkout -b <nameForYourTempBranch> <commitHash>
# deletion
git checkout <otherBranch>
git branch -D <nameForYourTempBranch>
However, in the case you want to keep the current state of the working tree unchanged for some reason, maybe consider adding a (temporary) new worktree. You can do that with
git worktree add <path/to/subdir> <commitHash>
It will allow you to make this inspection without modifying the current state of your main working tree.
Upvotes: 2
Reputation: 35037
You can go back a specific point of history with git checkout
and there are two easy ways to use it:
git log
and git checkout commit_id
git checkout HEAD~number_of_commits_you_want_to_go_back
e.g. git checkout HEAD~1
.Pay extra care to remember to go back to the future once you're finished looking at the old version. You can do that with git checkout HEAD
or git checkout name_of_branch
.
If you would like to use both the current and some other version of the file you will need to:
* have two copies of the repository since you can only have one working tree checked out
* make a copy of the current version before you use git checkout
Sites that provide git services often allow you to explore the history of files in your browser and often download the individual file or the entire repo at a given point.
Upvotes: 1