[git] Push a directory as a new commit
I am thinking of is it possible to create a new directory and push it as a commit to an existing repo?
So this directory originally does not have any .git folder.
Instead of cloning the entire repo and delete the directory in the first place.
Are there any commands that support this
65 Replies
Sounds like a git question, not a C# question?
There's a good git help channel on libera. https://web.libera.chat/ and join #git
So let's say i have an existing repo
Instead of cloning the entire repo and delete all the file
And add files to this directory
Then do
git commit "..."
Then do push
Is it possible just add the commit history to this folder and create a new commit and push to remoteDo you want to rewrite the existing history, or do you want to have a commit which removes everything from the previous commit?
so say originally there is 5 commits in the master branch
I want this folder with these files I just created to push as the 6th commit
Then you'll need to clone, as you need to know what the previous commit is to add your commit on top
cuz when you clone you download all the files of thee newest commit.
So I was thinking if it was possible to skip this download step and just create the commit
okay
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
that does not matter as long as you have non empty folder
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nah
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
you don't need it if you have non empty folder
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
tebeco#0205
THERE'S NO FOLDER
Quoted by
<@!689473681302224947> from #[git] Push a directory as a new commit (click here)
React with ❌ to remove this embed.
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
nah
when you donwload it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
it is a folder
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
and there is nothing to argue about this
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Folders are a thing. Empty folders are not
you can argue that cuz the uri and how git on the backend store thing
Folders map to trees. They're a first-class concept
but when you download a project of a folder with non empty folder
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
then it appears on your computer as folder
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
it really is not important at all
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
You're getting confused with AWS. Git has folders as a first-class concept. Definitely
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
no I wasn't
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Git doesn't track folders right? Only files
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I was never trying to have empty folder in the first place dude
That's why I know what you are talking about the first sentence you post
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
So
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
git ls-tree HEAD
shows the root tree for HEAD. That tree represents a folder. Please do some basic learning on git's internalsUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
I am careless about that man
Git doesn't use URIs
You are totally not on thee right track
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
The problem was never about how to push an empty folder
Git doesn't use full paths either
Please, this is basic stuff
Read the link I sent above
I couldve just googled that and understand that is not possible without knowing they save things as URI...
You've just added a ton of misinformation and confusion to this discussion
This thing about uri should never even started in this post
Git doesn't use URIs or full paths. They're thinking of object databases like S3 I think
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Don't get too hung up on packs. They're just a compressed form of commits/trees/blobs
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
1. Run
git cat-file -p HEAD
. That prints the commit object at HEAD. See the tree XXX
? That's the tree representing your root directory.
2. Run git cat-file -p XXX
(using the sha1 for the tree object above). That's the contents of your root directory. You should see a mixture of "blob"entries (files) and "tree" entries (sub-directories). You can keep doing that to explore the sub-folders in the commit
(there are nicer commands for doing that, but cat-file
is about as low-level as it gets, showing that trees really are a core first-class concept, and git doesn't use full paths)he's gone
What git doesn't support is an empty tree object
Eh, quitter
Anyway
When you create a commit (which isn't the first commit in a repo), you need to know the sha1 of the parent commit
I suppose you could construct the commit manually with
commit-tree
, but that's effort
Another option is to do a shallow clone with --depth 1
. That should still let you commit and push? And it'll just download the most recent commitwhat is --depth 1
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Aha, fair enough. I take that back!
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View