How to update git working copy to a specific commit while staying on the same branch? -
say have working copy on clean master
branch. want bring whole code state @ commit without switching commit / detaching head.
i can achieve using these steps:
- create copy of whole working copy directory;
- checkout new copy commit want code in state of;
- get rid of
.git
directory , bring 1 original working copy (that still @ cleanmaster
):
here example illustrating want in end:
mkdir code cd code/ git init . echo 'content 1' > file.txt git add --all && git commit -m 'version 1' && git tag v1 echo 'content 2' > file.txt git add --all && git commit -m 'version 2' && git tag v2 cd .. cp -pr code code1 cd code1/ git checkout v1 rm -rf .git mv ../code/.git ./ git diff diff --git a/file.txt b/file.txt index 4d4bc1c..a0054e4 100644 --- a/file.txt +++ b/file.txt @@ -1 +1 @@ -content 2 +content 1 git status on branch master changes not staged commit: modified: file.txt
the question is: how achieve using git commands , not juggling .git
folders? git bring-to-the-state-of hash/branch/tag
?
the previous answer appears give exacly want --patch
. answer title of question, can achieve using variant of checkout takes path
parameter.
so example, if have master
branch checked out , want update working directory files did in version 2.3.4
git checkout v2.3.4 -- .
this stage files have changed. issuing git status
show changed files.
Comments
Post a Comment