0

I have a branch detached from head in my repo where I add folder under the same name with different files in it. Every time when I want to commit something I manually delete the folder in my repository and add the new one with the same name but the different content in it, which I later commit and push. The problem is that when I checkout one of my past commits I see that folder and it contains content from the selected commit and the past commits, but I want to see content ONLY from that concrete commit. So, I want to ask is it possible to do so and how should I achieve that? Maybe I should delete the files from my repo using some kind of git command? (But if its true I want to make sure that the files from the last commits wont be lost).

JulioBordeaux
  • 494
  • 1
  • 7
  • 23

2 Answers2

1

Every time before committing, you should also remove from the tracked files all the files in the directory that git keep trace of, performing a git rm your_directory.

If you don't do it, git will remember that you had other files into the previous commit and will just add the differences, without removing the files that are not present in the new commit.

So you need to tell git that you are removing the files, and just after add again the new files with git add your_directory, after the copy of the new directory.

This way git will:

  • understand that it has to remove the old files/directory
  • add the new files/directory

You just have to do the same thing you are doing manually on the "filesystem level", and do it also at "git level".

Make me know if that is what you wanted to do! And if that worked!

Kamafeather
  • 8,663
  • 14
  • 69
  • 99
0

It seems like you want to see a commit without exposing its full history. I think the best way to do this is using an orphan branch.

You do -

git --orphan <new_branch>

This will switch you to a new branch which is clean and you can then checkout to your desired commit which will then be the parent commit without any history attached to it.

spock8190
  • 81
  • 4
  • This way won't he get a new branch for every commit he desires? Or this way all the commits for the *OP's directory copy* will still be resident into the same branch? – Kamafeather Aug 27 '14 at 13:10