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:

  1. create copy of whole working copy directory;
  2. checkout new copy commit want code in state of;
  3. get rid of .git directory , bring 1 original working copy (that still @ clean master):

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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -