[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
canton7
canton72y ago
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
KKSK@🌸🎵🌸🎵🌸
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 remote
canton7
canton72y ago
Do you want to rewrite the existing history, or do you want to have a commit which removes everything from the previous commit?
KKSK@🌸🎵🌸🎵🌸
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
canton7
canton72y ago
Then you'll need to clone, as you need to know what the previous commit is to add your commit on top
KKSK@🌸🎵🌸🎵🌸
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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
that does not matter as long as you have non empty folder
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
you don't need it if you have non empty folder
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX2y ago
tebeco#0205
THERE'S NO FOLDER
Quoted by
React with ❌ to remove this embed.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
nah when you donwload it
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
it is a folder
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
and there is nothing to argue about this
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
canton7
canton72y ago
Folders are a thing. Empty folders are not
KKSK@🌸🎵🌸🎵🌸
you can argue that cuz the uri and how git on the backend store thing
canton7
canton72y ago
Folders map to trees. They're a first-class concept
KKSK@🌸🎵🌸🎵🌸
but when you download a project of a folder with non empty folder
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
then it appears on your computer as folder
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
it really is not important at all
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
canton7
canton72y ago
You're getting confused with AWS. Git has folders as a first-class concept. Definitely
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
no I wasn't
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
mrphil2105
mrphil21052y ago
Git doesn't track folders right? Only files
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
canton7
canton72y ago
git ls-tree HEAD shows the root tree for HEAD. That tree represents a folder. Please do some basic learning on git's internals
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
I am careless about that man
canton7
canton72y ago
Git doesn't use URIs
KKSK@🌸🎵🌸🎵🌸
You are totally not on thee right track
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
KKSK@🌸🎵🌸🎵🌸
The problem was never about how to push an empty folder
canton7
canton72y ago
Git doesn't use full paths either Please, this is basic stuff Read the link I sent above
KKSK@🌸🎵🌸🎵🌸
I couldve just googled that and understand that is not possible without knowing they save things as URI...
canton7
canton72y ago
You've just added a ton of misinformation and confusion to this discussion
KKSK@🌸🎵🌸🎵🌸
This thing about uri should never even started in this post
canton7
canton72y ago
Git doesn't use URIs or full paths. They're thinking of object databases like S3 I think
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
canton7
canton72y ago
Don't get too hung up on packs. They're just a compressed form of commits/trees/blobs
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
canton7
canton72y ago
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)
KKSK@🌸🎵🌸🎵🌸
he's gone
canton7
canton72y ago
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 commit
KKSK@🌸🎵🌸🎵🌸
what is --depth 1
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
canton7
canton72y ago
Aha, fair enough. I take that back!
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server
More Posts