Say I have a branch "work" and a branch "ideas" in my git repository.
I usually work on my marvelous_file.cpp in "work" branch, but sometimes I would like to open at the same time the marvelous_file.cpp that is in my "ideas" branch.
I don't want to see what the differences between the two files, but rather take snippets of codes from the "ideas" branch and copy and past them in the file in the "work" branch.
Is this possible? If not, can I checkout the file in "ideas" into "work", but with a different name?
Git will simply copy the most recently-committed version of the file to your working directory, overwriting your copy. Therefore, it's crucial that you avoid this command unless you absolutely know that you don't want your unsaved local changes.
git checkout origin/master -- path/to/file // git checkout <local repo name (default is origin)>/<branch name> -- path/to/file will checkout the particular file from the downloaded changes (origin/master).
You can use git show
to do that:
git show ideas:marvelous_file.cpp
This will show it right in the Terminal. If you want that as a file, just pipe it into a file, e.g.:
git show ideas:marvelous_file.cpp > ideas.cpp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With