If you type "dir .git\objects /S /B" in CMD you can see all dirs, git objects and their hashes. Then if you type "more remaining_38_symbols_of_hash" inside of the appropriate directory, you get a weird output like:
☻Ед─lЖ┌╛°☼→SMмz⌂♠╒l2`l╡Y░2┘╨└└╠─D!/╡\пдвДс╚Гг/J♂r█"Ц?‼tg√ЄЫГ█>→кд$╡╕♦м╞БёQ╩ВЛw∟─╣fЮu╨`╛∙$Е⌂↨
Н╤)
Basically, how to get the info from an object without the "git cat-file" command or any external programming languages' libraries?
Related
My goal is to write an app that lets you quickly assign aliases to long directory paths and change to them. I wrote an app that manages them in a file in the user's appdata directory, but I can't find a way to change the directory of the shell I run the program in from my app. My goal is to have it work from git bash, cmd.exe, and powershell. I want something like this:
cd /c/vsts/some-long-project-name-reports
g -a reports
Now I have an alias 'reports' for that directory. What I want to do get to that directory next time I open a console is:
g reports
I'm using dotnet core, though looking through questions it seems like there isn't a way to do this at all. With Directory.SetCurrentDirectory(path); or Environment.CurrentDirectory = path; it changes the working directory of the g.exe process, but when it exits the shell goes back to it's working directory when I ran the command.
I've come up with a solution for git bash, I changed my g app to output the path instead and have this as go in my path:
OUTPUT="$(g $1)"
cd $OUTPUT
Then I just need to use . or source to run the script in the current shell:
. go reports
And batch file go.bat doesn't need the . or source to work:
for /F "tokens=*" %%i in ('g %1') do set OUTPUT=%%i
cd %OUTPUT%
I guess I'll have to live with typing the extra characters, but is there a similar way to do this with powershell?
Define a wrapper function in PowerShell (assuming that g.exe outputs the target path):
function g { Set-Location (g.exe $args) }
Generally, as eryksun points out in a comment, an executable - which by definition runs in a child process - cannot change its parent process' working directory.
Therefore, the only solution is to output the target directory's path and let the parent process change to it.
I recently had a git conflict, and rather than dealing with it properly, I didn't actually fix any of the conflicts, but did something like overwrite the files with another version from another clone of the repo, or moved the files out of the directory, or did a git reset --soft, or some other convoluted series of commands.
Anyway, I've been left with some files on my filesystem that I cannot delete. I cannot move them, rename them, delete them with DEL in the command line, or with RM in gitbash. The file is named:
pom.xml~9b19d48... dpom_refactor
It has 0 bytes, and I've no clue how to get rid of it. I no longer have any .git folder, so I can't use any git commands to rollback what I did. Whenever I attempt to delete/move/rename, I get the error:
Could not find this item
This is no longer located in C:\<filePath>. Verify the item's location and try again.
Any thoughts on how I could get rid of it?
This kind of invalid Windows filename could be dealt with like a nul file.
C:\> rename \\.\C:\..\pom.xml~9b19d48... dpom_refactor del.txt
C:\> del del.txt
Using the \\.\ prefix tells the high-level file I/O functions to pass the filename unparsed to the device driver
If that was to fail, only a dedicated tool (or Live Linux distro CD) would be able to mount that disk and remove the file.
Suppose I have a folder called Documents, with only one folder inside, called Projects, as illustrated incredibly below...
Documents
Projects
If I'm in Documents, is there a cmd line prompt which will take me into the only available folder, in this case Projects?
So instead of using
cd Projects
I'm looking for
cd 'only available folder'
Is there a cmd for this?
In response to an answer which was deleted: I'm not looking for a list of folder contents. I'm looking to navigate directly into the only available folder.
I suppose one option is:
cd 'Tab button'
There's not really a simple command for this. Like you suggested, the best solution, and what I would do, is cdspaceTab. Strictly speaking, there is a command that satisfies your requirements, but it's not exactly easy under the fingers.
for /d %I in (*) do cd "%I"
which would loop through all directories in the current directory (ostensibly, only one), then cd to it.
I have a huge series of folders, named 'A' through 'Z' such that each folder has subfolders in the same form.
For example, I could have a directory at this path: .\A\D\E
I want to populate each of these folders with an empty file (so I can commit it to a git repository if anyone's curious).
Windows doesn't have an equivalent of Linux's touch, but I have the GnuWin32 toolset installed so I can, in fact, use touch in my Windows environment.
I've started by creating a batch file with the following:
FOR /D /r do touch empty
But when I run it, the folders aren't populated. I don't get any errors either:
C:\sandbox>FOR /D /r do touch empty
C:\sandbox>
Does anybody see anything glaringly wrong about the line of batch script above? Is there anything else I can try short of using additional non-Windows commands?
You just need to get the syntax of the FOR command right:
for /r %f in (.) do touch %f\empty
Using Windows, Mercurial, and the extdiff extension (for Mercurial). I was trying to set up extdiff to use WinDiff as an external diff tool, but I think I've narrowed the problem down enough to say that the trouble is before I'm even getting that far.
From what I understand of extdiff, it merely calls your cmd.winmerge program, and passes the necessary directories to it. I'm also working off of some assumptions outlined here (which may or may not be accurate; I'm just learning Mercurial):
http://bitbucket.org/tortoisehg/stable/issue/457/multiple-extdiff-threads-in-one-process-causes-side#comment-36216
which says:
The extdiff (visual diff) extension works like this:
1-Generate temporary directory(ies) for older changesets
2-run util.system( cwd=tempdir, "yourdiff tool dir1 dir2" )
util.system does:
2.1 store cwd;
2.2 cd tempdir
3-run your diff tool, wait for it to exit
4-cd oldcwd
5-Then finally extdiff deletes the temp directories.
The trouble that I'm having is that extdiff doesn't seem to be changing into the temp directory before proceeding, as it appears it is supposed to do in step 2.1 above.
In trying to isolate the problem, I wrote a batch file just to see what the cd was, what was being passed, and how exactly it was being passed. The batch file is as follows:
#echo off
echo %cd%
echo %1
echo %2
D:\Documents\apps\WinMergePortable\App\WinMerge\WinMergeU.exe %1 %2
I then set up extdiff to use this batch file as my extdiff program. This works, but I see that when it echoes %cd%, it's just c:\ , not c:\temp as expected. I've verified that extdiff is creating the temporary files in the proper temporary directories (as it's supposed to per step 1 above; something like c:\temp\extdiff.xxxxxx\someFolder.someChangesetID\file.ext), so I know it's SEEING those directories. It's just not properly changing into them before it's calling WinMerge, so when WinMerge is opened, it doesn't see the temp files (since it's not in the proper working directory).
That's basically where I'm stuck. I don't know where else to go from here. I thought of just putting
cd %tmp%
in my batch file, but that still doesn't grab the extdiff.xxxxx\ subdirectory which extdiff is creating the temp files in.
In summary: :-(
EDIT: Changing the batch file to
#echo off
echo %cd%\extdiff*
echo %1
echo %2
D:\Documents\apps\WinMergePortable\App\WinMerge\WinMergeU.exe %1 %2
seems to make it work (note changed second line), but it still seems a nasty hack to instead of how it's supposed to work. :-\
EDIT: Here is my Mercurial.ini file:
[ui]
username = Tim Skoch <my_real#email.address>
editor = D:\Documents\apps\Notepad++\notepad++.exe -multiInst
[extensions]
hgext.graphlog =
hgext.extdiff =
[extdiff]
cmd.winmerge = d:\Documents\apps\mercurial\diff_winmerge.bat
I can confirm that extdiff will change to a temporary directory before starting your diff program. You can use --debug to see this. Here I'm using true as the diff program (it just exist immediately):
$ hg extdiff -p true --debug
making snapshot of 2 files from rev 18480437f81b
a
b
making snapshot of 2 files from working directory
a
b
running "'true' 'foo.18480437f81b' 'foo'" in /tmp/extdiff.IJ9clg
cleaning up temp directory
The two arguments for the diff program are directories: a snapshot directory for the old versions and one for the new versions. They are inside the /tmp/extdiff.IJ9clg temporary directory.
One confusing point is that the arguments for the diff program are different depending on the number of modified files. With just one modified file, there is no need to create a
snapshot of the working copy. So if a is the only modified file, you'll see
$ hg extdiff -p true --debug
making snapshot of 1 files from rev 18480437f81b
a
running "'true' '/tmp/extdiff.mUlnP_/foo.18480437f81b/a' '/home/mg/tmp/foo/a'"
in /tmp/extdiff.mUlnP_
cleaning up temp directory
Here the diff program was started with two files as arguments. As described in hg help -e extdiff, you can use some variables to build the command line. The default corresponds to $parent $child.
You say that WinMerge "cannot find the files correctly". There are other questions and answers on SO about WinMerge and they seem to have it working just fine. Maybe you can try their command line options.