有没有办法使用命令git ls-files
,只显示未跟踪的文件?
我问的原因是因为我使用以下命令来处理所有已删除的文件:
git ls-files -d | xargs git rm
Run Code Online (Sandbox Code Playgroud)
对于未跟踪的文件,我想要类似的东西:
git some-command --some-options | xargs git add
Run Code Online (Sandbox Code Playgroud)
我能够找到-o
选项git ls-files
,但这不是我想要的,因为它也显示了被忽略的文件.我还能够提出以下长而丑陋的命令:
git status --porcelain | grep '^??' | cut -c4- | xargs git add
Run Code Online (Sandbox Code Playgroud)
似乎我必须在这里使用更好的命令.如果没有,我如何创建自定义git命令?
我想删除对我的工作副本的所有更改.
运行git status
显示修改的文件.
我没做什么似乎删除了这些修改.
例如:
rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
# modified: Rhino.Etl.Core/Pipelines/SingleThreadedPipelineExecuter.cs
# modified: Rhino.Etl.Tests/Rhino.Etl.Tests.csproj
# modified: Rhino.Etl.Tests/SingleThreadedPipelineExecuterTest.cs
#
no changes added to commit (use "git add" and/or "git commit -a")
rbellamy@PROMETHEUS /d/Development/rhino-etl (master)
$ git checkout -- Rhino.Etl.Core/Enumerables/CachingEnumerable.cs
rbellamy@PROMETHEUS …
Run Code Online (Sandbox Code Playgroud) 目标是获得可以在shell命令中评估的明确状态.
我试过git status
但它总是返回0,即使有提交的项目.
git status
echo $? #this is always 0
Run Code Online (Sandbox Code Playgroud)
我有一个想法,但我认为这是一个坏主意.
if [ git status | grep -i -c "[a-z]"> 2 ];
then
code for change...
else
code for nothing change...
fi
Run Code Online (Sandbox Code Playgroud)
任何其他方式?
通过以下解决更新,请参阅Mark Longair的帖子
我尝试了这个,但它导致了一个问题.
if [ -z $(git status --porcelain) ];
then
echo "IT IS CLEAN"
else
echo "PLEASE COMMIT YOUR CHANGE FIRST!!!"
echo git status
fi
Run Code Online (Sandbox Code Playgroud)
我收到以下错误 [: ??: binary operator expected
现在,我正在看那个男人并尝试git diff.
===================代码为我的希望,希望更好的答案======================
#if [ `git status | grep -i -c "$"` …
Run Code Online (Sandbox Code Playgroud) 我上传了很多文件git add
,现在我希望看到我上传的所有文件,无论有git diff --cached
没有git status --cached
.
我怎么做?使用时,--cached
我可以看到我刚刚上演的变化..所以然后我尝试使用,git status
但git add
不幸的是,这不起作用git diff --cached
.
我想着色git-status输出,以便:
untracked files = magenta
new files = green
modified files = blue
deleted files = red
Run Code Online (Sandbox Code Playgroud)
我反而看到绿色和非分页文件中的分段文件为蓝色:
我的.gitconfig根据一些搜索设置如下:
[color]
status = auto
[color "status"]
added = green
changed = blue
untracked = magenta
deleted = red
Run Code Online (Sandbox Code Playgroud) 此命令用于获取文件并编译它们:
git clone a-valid-git-url
Run Code Online (Sandbox Code Playgroud)
例如:
git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts
Run Code Online (Sandbox Code Playgroud)
但是,git status
(或任何其他git命令)然后给出上述fatal: Not a git repository (or any of the parent directories)
错误.
我究竟做错了什么?
我有一个项目与某些js文件,我无法更新.我在本地运行OSX,而我的远程/临时服务器是Linux(CentOS).
在本地克隆我的项目后,我注意到我有所有那些具有git状态的文件modified
.我从来没有修改它们,所以我尝试了discard changes
或者reset
它们,但它们再次出现.修改中的更改是删除所有行并再次添加它们.
我不确定为什么会发生这种情况或如何解决它,以便我的git状态是干净的,因为它需要.
以下是git状态的几行:
# modified: app/webroot/js/ckeditor/plugins/devtools/lang/el.js
# modified: app/webroot/js/ckeditor/plugins/devtools/lang/fa.js
# modified: app/webroot/js/ckeditor/plugins/devtools/lang/gu.js
Run Code Online (Sandbox Code Playgroud)
更新1:
我现在设法提交上述文件,但登台服务器被锁定,因为它不会提取新的编辑:
error: Your local changes to the following files would be overwritten by merge:
app/webroot/js/ckeditor/_source/lang/ar.js
app/webroot/js/ckeditor/_source/lang/bg.js
app/webroot/js/ckeditor/_source/lang/bn.js
app/webroot/js/ckeditor/_source/lang/cs.js
...
Aborting
Run Code Online (Sandbox Code Playgroud)
我无法提交/推送,因为:
Updates were rejected because a pushed branch tip is behind its remote counterpart
Run Code Online (Sandbox Code Playgroud)
我试过了:
git reset --hard
Run Code Online (Sandbox Code Playgroud)
和
git stash
git stash drop
Run Code Online (Sandbox Code Playgroud)
但它们不起作用,没有任何反应.
更新2:
git diff
给我:
The file will have its original line endings in your …
Run Code Online (Sandbox Code Playgroud) 我想获得一个只有分阶段文件名的列表.我找不到--name-only
该git status
命令的等效标志.什么是好的选择?
文件列表将通过管道传递给php -l
(PHP lint语法检查器).
解决方案:完整的命令
git diff --name-only --cached | xargs -l php -l
Run Code Online (Sandbox Code Playgroud) 我想提取a之后打印的信息,git status
如下所示:
# On branch master
# Your branch is ahead of 'origin/master' by 2 commits.
Run Code Online (Sandbox Code Playgroud)
当然我可以解析输出,git status
但不建议这样做,因为这个人类可读输出容易改变.
有两个问题:
origin/branch
但不一定是这样.如果我在我的仓库上运行'git status',它会给出:
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# modified: myfile
Run Code Online (Sandbox Code Playgroud)
但是,如果我执行'git diff myfile',它就没有显示出任何差异.这是因为我做了一个更改并将其删除,以便恢复原状吗?
我应该运行'git checkout myfile'来清除它吗?
git ×10
git-status ×10
git-diff ×2
git-stage ×2
clone ×1
git-clone ×1
git-config ×1
git-ls-files ×1
git-rm ×1
repository ×1
revert ×1
working-copy ×1